aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2020-12-13 12:35:33 +0100
committerMarvin Borner2020-12-13 12:35:33 +0100
commitfc4981e3ea863632c88e5f0b308ae4532d077e49 (patch)
tree811a1d2c09cd811764fb8c3c09099a876beb0e7f
parentf476fb5eaf30254dcb9e480f27f52b207147e207 (diff)
Added execution timers
-rw-r--r--2020/01/solve.cs3
-rw-r--r--2020/02/solve.c5
-rw-r--r--2020/03/solve.c5
-rw-r--r--2020/04/solve.c7
-rw-r--r--2020/05/solve.c4
-rw-r--r--2020/06/solve.js4
-rw-r--r--2020/07/solve.js4
-rw-r--r--2020/08/solve.js4
-rw-r--r--2020/09/solve.js4
-rw-r--r--2020/10/solve.c4
-rw-r--r--2020/11/solve.c5
-rw-r--r--2020/12/solve.c4
-rw-r--r--2020/13/solve.c5
-rw-r--r--2020/Makefile7
-rw-r--r--2020/README13
15 files changed, 72 insertions, 6 deletions
diff --git a/2020/01/solve.cs b/2020/01/solve.cs
index fb2f6ae..70604c5 100644
--- a/2020/01/solve.cs
+++ b/2020/01/solve.cs
@@ -49,11 +49,14 @@ namespace AOC
string text = File.ReadAllText("input");
string[] numsStr = text.Split('\n');
numsStr[numsStr.Length - 1] = "2020"; // Some weird newline character ig
+ var clock = System.Diagnostics.Stopwatch.StartNew();
int[] nums = Array.ConvertAll(numsStr, int.Parse).OrderBy(i => i).ToArray();
int[] d = Double(nums, 0, 2020);
int[] t = Triple(nums, 2020);
Console.WriteLine(d[0] * d[1]);
Console.WriteLine(t[0] * t[1] * t[2]);
+ clock.Stop();
+ Console.WriteLine("TIME: " + ((float)clock.ElapsedMilliseconds / 1000.0).ToString("n6") + " seconds");
}
}
}
diff --git a/2020/02/solve.c b/2020/02/solve.c
index 6294771..9a1631b 100644
--- a/2020/02/solve.c
+++ b/2020/02/solve.c
@@ -1,6 +1,6 @@
-#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
+#include <time.h>
int part_one(FILE *fp)
{
@@ -51,9 +51,12 @@ int main(int argc, char *argv[])
if (!fp)
exit(EXIT_FAILURE);
+ clock_t tic = clock();
printf("%d\n", part_one(fp));
rewind(fp);
printf("%d\n", part_two(fp));
+ clock_t toc = clock();
+ printf("TIME: %f seconds\n", (double)(toc - tic) / CLOCKS_PER_SEC);
fclose(fp);
return 0;
diff --git a/2020/03/solve.c b/2020/03/solve.c
index 2f6312b..e427764 100644
--- a/2020/03/solve.c
+++ b/2020/03/solve.c
@@ -1,6 +1,6 @@
-#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
+#include <time.h>
int part_one(FILE *fp)
{
@@ -48,9 +48,12 @@ int main(int argc, char *argv[])
if (!fp)
exit(EXIT_FAILURE);
+ clock_t tic = clock();
printf("%d\n", part_one(fp));
rewind(fp);
printf("%u\n", part_two(fp));
+ clock_t toc = clock();
+ printf("TIME: %f seconds\n", (double)(toc - tic) / CLOCKS_PER_SEC);
fclose(fp);
return 0;
diff --git a/2020/04/solve.c b/2020/04/solve.c
index a613660..8227c4b 100644
--- a/2020/04/solve.c
+++ b/2020/04/solve.c
@@ -1,8 +1,8 @@
-#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
void normalize(char *data)
{
@@ -146,10 +146,13 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
char buf[SIZE] = { 0 };
fread(buf, SIZE, 1, fp);
- normalize(buf);
+ clock_t tic = clock();
+ normalize(buf);
printf("%d\n", part_one(buf));
printf("%d\n", part_two(buf));
+ clock_t toc = clock();
+ printf("TIME: %f seconds\n", (double)(toc - tic) / CLOCKS_PER_SEC);
fclose(fp);
return 0;
diff --git a/2020/05/solve.c b/2020/05/solve.c
index 025b644..1f6a9b4 100644
--- a/2020/05/solve.c
+++ b/2020/05/solve.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <time.h>
#define COUNT 1024
#define FIRST 100
@@ -95,8 +96,11 @@ int main(int argc, char *argv[])
if (!fp)
exit(EXIT_FAILURE);
+ clock_t tic = clock();
printf("%d\n", part_one(fp));
printf("%d\n", part_two());
+ clock_t toc = clock();
+ printf("TIME: %f seconds\n", (double)(toc - tic) / CLOCKS_PER_SEC);
fclose(fp);
return 0;
diff --git a/2020/06/solve.js b/2020/06/solve.js
index e82242a..c3907cf 100644
--- a/2020/06/solve.js
+++ b/2020/06/solve.js
@@ -1,3 +1,4 @@
+const { _, performance } = require("perf_hooks");
const fs = require("fs");
const data = fs.readFileSync("input", "utf8");
@@ -22,5 +23,8 @@ function part_two()
return res;
}
+const tic = performance.now();
console.log(part_one());
console.log(part_two());
+const toc = performance.now();
+console.log("TIME: " + ((toc - tic) / 1000).toFixed(6) + " seconds");
diff --git a/2020/07/solve.js b/2020/07/solve.js
index 28359e6..c4bbfae 100644
--- a/2020/07/solve.js
+++ b/2020/07/solve.js
@@ -1,3 +1,4 @@
+const { _, performance } = require("perf_hooks");
const fs = require("fs");
const data = fs.readFileSync("input", "utf8").split('\n');
@@ -45,5 +46,8 @@ function partTwo()
return countBags(map, "shiny gold");
}
+const tic = performance.now();
console.log(partOne());
console.log(partTwo());
+const toc = performance.now();
+console.log("TIME: " + ((toc - tic) / 1000).toFixed(6) + " seconds");
diff --git a/2020/08/solve.js b/2020/08/solve.js
index c03edcb..68006d6 100644
--- a/2020/08/solve.js
+++ b/2020/08/solve.js
@@ -1,3 +1,4 @@
+const { _, performance } = require("perf_hooks");
const fs = require("fs");
const data = fs.readFileSync("input", "utf8").split('\n');
@@ -48,5 +49,8 @@ function partTwo()
}
}
+const tic = performance.now();
console.log(partOne());
console.log(partTwo());
+const toc = performance.now();
+console.log("TIME: " + ((toc - tic) / 1000).toFixed(6) + " seconds");
diff --git a/2020/09/solve.js b/2020/09/solve.js
index 394bd4b..f1289c7 100644
--- a/2020/09/solve.js
+++ b/2020/09/solve.js
@@ -1,3 +1,4 @@
+const { _, performance } = require("perf_hooks");
const fs = require("fs");
const data = fs
.readFileSync("input", "utf8")
@@ -40,6 +41,9 @@ function partTwo(num) {
}
}
+const tic = performance.now();
const num = partOne();
console.log(num);
console.log(partTwo(num));
+const toc = performance.now();
+console.log("TIME: " + ((toc - tic) / 1000).toFixed(6) + " seconds");
diff --git a/2020/10/solve.c b/2020/10/solve.c
index 0eb8970..8100297 100644
--- a/2020/10/solve.c
+++ b/2020/10/solve.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <time.h>
static int LENGTH = 0;
@@ -72,8 +73,11 @@ int main()
to_int(fp, data);
qsort(data, LENGTH, sizeof(int), cmp);
+ clock_t tic = clock();
printf("%d\n", part_one(data));
printf("%lu\n", part_two(data));
+ clock_t toc = clock();
+ printf("TIME: %f seconds\n", (double)(toc - tic) / CLOCKS_PER_SEC);
fclose(fp);
return 0;
diff --git a/2020/11/solve.c b/2020/11/solve.c
index 2b613cf..d69fd36 100644
--- a/2020/11/solve.c
+++ b/2020/11/solve.c
@@ -1,8 +1,8 @@
-#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#define SIZE 10000
#define X_MAX 99
@@ -201,8 +201,11 @@ int main(int argc, char *argv[])
char buf[SIZE] = { 0 };
fread(buf, SIZE, 1, fp);
+ clock_t tic = clock();
printf("%d\n", part_one(buf));
printf("%d\n", part_two(buf));
+ clock_t toc = clock();
+ printf("TIME: %f seconds\n", (double)(toc - tic) / CLOCKS_PER_SEC);
fclose(fp);
return 0;
diff --git a/2020/12/solve.c b/2020/12/solve.c
index 111f689..fb10141 100644
--- a/2020/12/solve.c
+++ b/2020/12/solve.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <time.h>
enum dir { N, E, S, W };
@@ -136,9 +137,12 @@ int main(int argc, char *argv[])
if (!fp)
exit(EXIT_FAILURE);
+ clock_t tic = clock();
printf("%d\n", part_one(fp));
rewind(fp);
printf("%d\n", part_two(fp));
+ clock_t toc = clock();
+ printf("TIME: %f seconds\n", (double)(toc - tic) / CLOCKS_PER_SEC);
fclose(fp);
return 0;
diff --git a/2020/13/solve.c b/2020/13/solve.c
index dde2ed1..5cb45d1 100644
--- a/2020/13/solve.c
+++ b/2020/13/solve.c
@@ -1,7 +1,7 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
+#include <time.h>
int part_one(char *data)
{
@@ -78,8 +78,11 @@ int main(int argc, char *argv[])
char buf[SIZE] = { 0 };
fread(buf, SIZE, 1, fp);
+ clock_t tic = clock();
printf("%d\n", part_one(buf));
printf("%lu\n", part_two(buf));
+ clock_t toc = clock();
+ printf("TIME: %f seconds\n", (double)(toc - tic) / CLOCKS_PER_SEC);
fclose(fp);
return 0;
diff --git a/2020/Makefile b/2020/Makefile
new file mode 100644
index 0000000..033d272
--- /dev/null
+++ b/2020/Makefile
@@ -0,0 +1,7 @@
+SUBDIRS := $(wildcard *)
+
+all: $(SUBDIRS)
+$(SUBDIRS):
+ @if [ -d "$@" ]; then echo "Day $@: $$(make -C $@ run | grep 'TIME')"; fi
+
+.PHONY: all $(SUBDIRS)
diff --git a/2020/README b/2020/README
new file mode 100644
index 0000000..d4c7ca5
--- /dev/null
+++ b/2020/README
@@ -0,0 +1,13 @@
+Day 01: TIME: 0.006000 seconds
+Day 02: TIME: 0.001094 seconds
+Day 03: TIME: 0.000053 seconds
+Day 04: TIME: 0.003551 seconds
+Day 05: TIME: 0.000491 seconds
+Day 06: TIME: 0.018786 seconds
+Day 07: TIME: 0.046968 seconds
+Day 08: TIME: 0.021613 seconds
+Day 09: TIME: 0.013302 seconds
+Day 10: TIME: 0.000010 seconds
+Day 11: TIME: 0.037025 seconds
+Day 12: TIME: 0.000236 seconds
+Day 13: TIME: 0.000024 seconds