Alter main() to run benchmark instead of single puzzle
This commit is contained in:
parent
39d417f2bc
commit
ef7f0f0f73
61
main.c
61
main.c
@ -23,6 +23,9 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define PROG_UPDATEPRD 20
|
||||||
|
#define NPUZZLES 1024U
|
||||||
|
|
||||||
static uint32_t getseed(void)
|
static uint32_t getseed(void)
|
||||||
{
|
{
|
||||||
FILE *urandom = fopen("/dev/urandom", "rb");
|
FILE *urandom = fopen("/dev/urandom", "rb");
|
||||||
@ -44,19 +47,53 @@ int main(void)
|
|||||||
printf("Seed: %u\n\n", seed);
|
printf("Seed: %u\n\n", seed);
|
||||||
srand(seed);
|
srand(seed);
|
||||||
|
|
||||||
struct sudoku sud;
|
struct sudoku puzzles[NPUZZLES];
|
||||||
gen(&sud);
|
unsigned i, j, bslen = 0;
|
||||||
puts("Start:");
|
fputs("Generating... ", stdout);
|
||||||
print(&sud);
|
for (i = 0; i < NPUZZLES; ++i) {
|
||||||
putchar('\n');
|
if (i % PROG_UPDATEPRD == 0) {
|
||||||
|
for (j = 0; j < bslen; ++j)
|
||||||
bool res = solve(&sud);
|
putchar('\b');
|
||||||
if (!res) {
|
bslen = (unsigned)printf("%u%%", 100 * i / NPUZZLES);
|
||||||
puts("Solver encountered an error\n");
|
fflush(stdout);
|
||||||
} else {
|
|
||||||
puts("End:");
|
|
||||||
print(&sud);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gen(&puzzles[i]);
|
||||||
|
}
|
||||||
|
for (j = 0; j < bslen; ++j)
|
||||||
|
putchar('\b');
|
||||||
|
puts("100%");
|
||||||
|
|
||||||
|
bool res[NPUZZLES];
|
||||||
|
fputs("Solving... ", stdout);
|
||||||
|
for (i = 0; i < NPUZZLES; ++i)
|
||||||
|
res[i] = solve(&puzzles[i]);
|
||||||
|
puts("done");
|
||||||
|
|
||||||
|
unsigned error = 0, incomplete = 0, incorrect = 0, solved = 0;
|
||||||
|
for (i = 0; i < NPUZZLES; ++i) {
|
||||||
|
if (!res[i]) {
|
||||||
|
++error;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
switch (check(&puzzles[i])) {
|
||||||
|
case INCOMPLETE:
|
||||||
|
++incomplete;
|
||||||
|
break;
|
||||||
|
case INCORRECT:
|
||||||
|
++incorrect;
|
||||||
|
break;
|
||||||
|
case SOLVED:
|
||||||
|
++solved;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
puts("\n SUMMARY\n =======");
|
||||||
|
printf("Solved: %4u/%u\n", solved, NPUZZLES);
|
||||||
|
printf("Incomplete: %4u/%u\n", incomplete, NPUZZLES);
|
||||||
|
printf("Incorrect: %4u/%u\n", incorrect, NPUZZLES);
|
||||||
|
printf("Solver error: %4u/%u\n", error, NPUZZLES);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user