Pass benchmark results out via pointer

This commit is contained in:
Camden Dixie O'Brien 2022-11-23 18:07:21 +00:00
parent 37e7c6481a
commit 3fa089e4af

17
main.c
View File

@ -30,7 +30,7 @@
struct bench_res { struct bench_res {
double succ_rate; double succ_rate;
double avg_time_us; double avg_time_us;
unsigned avg_passes; double avg_passes;
}; };
static uint32_t getseed(void) static uint32_t getseed(void)
@ -75,7 +75,7 @@ static void genpuzzles(struct sudoku puzzles_out[NPUZZLES],
} }
} }
static struct bench_res runbench(struct sudoku puzzles[NPUZZLES]) static void runbench(struct sudoku puzzles[NPUZZLES], struct bench_res *res_out)
{ {
int res[NPUZZLES]; int res[NPUZZLES];
unsigned i; unsigned i;
@ -106,11 +106,9 @@ static struct bench_res runbench(struct sudoku puzzles[NPUZZLES])
tot_passes += (unsigned long)res[i]; tot_passes += (unsigned long)res[i];
} }
return (struct bench_res) { res_out->succ_rate = (double)solved / NPUZZLES;
.succ_rate = (double)solved / NPUZZLES, res_out->avg_time_us = tot_micros / NPUZZLES;
.avg_time_us = tot_micros / NPUZZLES, res_out->avg_passes = (double)tot_passes / NPUZZLES;
.avg_passes = tot_passes / NPUZZLES,
};
} }
int main(void) int main(void)
@ -120,13 +118,14 @@ int main(void)
srand(seed); srand(seed);
struct sudoku puzzles[NPUZZLES]; struct sudoku puzzles[NPUZZLES];
struct bench_res res;
genpuzzles(puzzles, 0.33, true); genpuzzles(puzzles, 0.33, true);
struct bench_res res = runbench(puzzles); runbench(puzzles, &res);
puts("\n SUMMARY\n ======="); puts("\n SUMMARY\n =======");
printf("Success rate: %.0lf%%\n", 1e2 * res.succ_rate); printf("Success rate: %.0lf%%\n", 1e2 * res.succ_rate);
printf("Average time: %.3lf µs\n", res.avg_time_us); printf("Average time: %.3lf µs\n", res.avg_time_us);
printf("Average n.o. passes: %u\n", res.avg_passes); printf("Average n.o. passes: %0.3lf\n", res.avg_passes);
return 0; return 0;
} }