Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions benches/qsolvebench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,46 @@ fn benchmark_puzzle(c: &mut Criterion, name: &str, file: &str) {
let mut g = c.benchmark_group(name);
g.measurement_time(Duration::from_secs(10));
g.sample_size(500);
g.bench_function("Fast", |b| {
for (label, strategy) in [
("Fast", SolveStrategy::Fast),
("Simple", SolveStrategy::Simple),
("Short", SolveStrategy::Short),
] {
g.bench_function(label, |b| {
let content = std::fs::read_to_string(file).unwrap();
let board = Board::from_str(&content).unwrap();
b.iter(|| {
let solve_state = SolveState::from(&board);
let heuristics = all_heuristics(black_box(&board));
let state_iter_items =
solve_iter(solve_state, strategy, &heuristics).collect::<Vec<_>>();
let _final_state = black_box(&state_iter_items.iter().last().unwrap().solve_state);
})
});
}
g.finish();
}

fn benchmark_board_construction(c: &mut Criterion) {
let mut g = c.benchmark_group("BoardConstruction");
g.measurement_time(Duration::from_secs(10));
g.sample_size(500);
for (name, file) in [
("LinkedIn1", "games/linkedin-1-empty.txt"),
("GameOfCrowns1", "games/gameofcrowns-1.txt"),
] {
let content = std::fs::read_to_string(file).unwrap();
let board = Board::from_str(&content).unwrap();
b.iter(|| {
let solve_state = SolveState::from(&board);
let heuristics = all_heuristics(black_box(&board));
let state_iter_items =
solve_iter(solve_state, SolveStrategy::Fast, &heuristics).collect::<Vec<_>>();
let _final_state = black_box(&state_iter_items.iter().last().unwrap().solve_state);
})
});
g.bench_function(name, |b| {
b.iter(|| black_box(Board::from_str(black_box(content.as_str())).unwrap()))
});
}
g.finish();
}

fn criterion_benchmark(c: &mut Criterion) {
benchmark_puzzle(c, "LinkedIn1", "games/linkedin-1-empty.txt");
benchmark_puzzle(c, "GameOfCrowns1", "games/gameofcrowns-1.txt");
benchmark_board_construction(c);
}

criterion_group!(benches, criterion_benchmark);
Expand Down
Loading