diff --git a/Makefile b/Makefile index b004aaf..61abfd4 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ CFLAGS += -std=c11 -pedantic -Wall -Wextra CFLAGS += -O2 -flto +CFLAGS += -D_XOPEN_SOURCE=700 SRC = main.c sud.c solve.c OBJ = $(SRC:.c=.o) diff --git a/main.c b/main.c index 969d84c..1707aa9 100644 --- a/main.c +++ b/main.c @@ -22,6 +22,7 @@ #include #include #include +#include #define PROG_UPDATEPRD 20 #define NPUZZLES 1024U @@ -65,11 +66,24 @@ int main(void) puts("100%"); bool res[NPUZZLES]; + struct timespec start, end; fputs("Solving... ", stdout); + fflush(stdout); + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); for (i = 0; i < NPUZZLES; ++i) res[i] = solve(&puzzles[i]); + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); puts("done"); + long secs = end.tv_sec - start.tv_sec; + long nanos = end.tv_nsec - start.tv_nsec; + if (nanos < 0) { + --secs; + nanos += 1000000000; + } + const double tot_micros = 1e6 * (double)secs + (double)nanos / 1e3; + const double avg_micros = tot_micros / NPUZZLES; + unsigned error = 0, incomplete = 0, incorrect = 0, solved = 0; for (i = 0; i < NPUZZLES; ++i) { if (!res[i]) { @@ -90,6 +104,7 @@ int main(void) } puts("\n SUMMARY\n ======="); + printf("Average time: %.3lf µs\n", avg_micros); printf("Solved: %4u/%u\n", solved, NPUZZLES); printf("Incomplete: %4u/%u\n", incomplete, NPUZZLES); printf("Incorrect: %4u/%u\n", incorrect, NPUZZLES);