-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.cpp
More file actions
53 lines (43 loc) · 1.64 KB
/
Copy pathbenchmark.cpp
File metadata and controls
53 lines (43 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "benchmark.hpp"
#include "solver.hpp"
#include <array>
#include <iomanip>
#include <iostream>
#include <string>
void runBenchmark(const Board& puzzle) {
struct BenchmarkCase {
std::string name;
SolverOptions options;
};
SolverOptions normalDfs;
normalDfs.useMrv = false;
normalDfs.usePropagation = false;
normalDfs.useOptimizedIteration = false;
SolverOptions mrvOnly;
mrvOnly.usePropagation = false;
SolverOptions mrvWithPropagation;
SolverOptions uniquenessCheck;
uniquenessCheck.solutionLimit = 2;
std::array<BenchmarkCase, 4> cases{{
{"Normal DFS, simple digit loop", normalDfs},
{"MRV only", mrvOnly},
{"MRV + propagation", mrvWithPropagation},
{"Uniqueness check", uniquenessCheck},
}};
std::cout << "\nBenchmark:\n";
std::cout << std::left << std::setw(30) << "Mode"
<< std::right << std::setw(12) << "Calls"
<< std::setw(12) << "Backtracks"
<< std::setw(12) << "Depth"
<< std::setw(12) << "Time(ms)"
<< " Result\n";
for (const auto& benchmarkCase : cases) {
SolveReport report = solveSudoku(puzzle, benchmarkCase.options);
std::cout << std::left << std::setw(30) << benchmarkCase.name
<< std::right << std::setw(12) << report.stats.recursiveCalls
<< std::setw(12) << report.stats.backtracks
<< std::setw(12) << report.stats.maxDepth
<< std::setw(12) << std::fixed << std::setprecision(3) << report.stats.elapsedMs
<< " " << statusName(report.status) << '\n';
}
}