Add timing to benchmarks
This commit is contained in:
parent
ef7f0f0f73
commit
14eb8533e6
1
Makefile
1
Makefile
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
CFLAGS += -std=c11 -pedantic -Wall -Wextra
|
CFLAGS += -std=c11 -pedantic -Wall -Wextra
|
||||||
CFLAGS += -O2 -flto
|
CFLAGS += -O2 -flto
|
||||||
|
CFLAGS += -D_XOPEN_SOURCE=700
|
||||||
|
|
||||||
SRC = main.c sud.c solve.c
|
SRC = main.c sud.c solve.c
|
||||||
OBJ = $(SRC:.c=.o)
|
OBJ = $(SRC:.c=.o)
|
||||||
|
15
main.c
15
main.c
@ -22,6 +22,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#define PROG_UPDATEPRD 20
|
#define PROG_UPDATEPRD 20
|
||||||
#define NPUZZLES 1024U
|
#define NPUZZLES 1024U
|
||||||
@ -65,11 +66,24 @@ int main(void)
|
|||||||
puts("100%");
|
puts("100%");
|
||||||
|
|
||||||
bool res[NPUZZLES];
|
bool res[NPUZZLES];
|
||||||
|
struct timespec start, end;
|
||||||
fputs("Solving... ", stdout);
|
fputs("Solving... ", stdout);
|
||||||
|
fflush(stdout);
|
||||||
|
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start);
|
||||||
for (i = 0; i < NPUZZLES; ++i)
|
for (i = 0; i < NPUZZLES; ++i)
|
||||||
res[i] = solve(&puzzles[i]);
|
res[i] = solve(&puzzles[i]);
|
||||||
|
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end);
|
||||||
puts("done");
|
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;
|
unsigned error = 0, incomplete = 0, incorrect = 0, solved = 0;
|
||||||
for (i = 0; i < NPUZZLES; ++i) {
|
for (i = 0; i < NPUZZLES; ++i) {
|
||||||
if (!res[i]) {
|
if (!res[i]) {
|
||||||
@ -90,6 +104,7 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
puts("\n SUMMARY\n =======");
|
puts("\n SUMMARY\n =======");
|
||||||
|
printf("Average time: %.3lf µs\n", avg_micros);
|
||||||
printf("Solved: %4u/%u\n", solved, NPUZZLES);
|
printf("Solved: %4u/%u\n", solved, NPUZZLES);
|
||||||
printf("Incomplete: %4u/%u\n", incomplete, NPUZZLES);
|
printf("Incomplete: %4u/%u\n", incomplete, NPUZZLES);
|
||||||
printf("Incorrect: %4u/%u\n", incorrect, NPUZZLES);
|
printf("Incorrect: %4u/%u\n", incorrect, NPUZZLES);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user