Skip to content

Commit 19aa329

Browse files
committed
Add bench for backtracking
1 parent 33f68e4 commit 19aa329

File tree

5 files changed

+48
-4
lines changed

5 files changed

+48
-4
lines changed

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ include = ["Cargo.toml", "LICENSE", "README.md", "src/**", "tests/**", "examples
2424

2525
[dependencies]
2626
indexmap = "2.6.0"
27-
log = "0.4.22" # for debug logs in tests
27+
# for debug logs in tests
28+
log = "0.4.22"
2829
priority-queue = "2.1.1"
2930
rustc-hash = ">=1.0.0, <3.0.0"
3031
serde = { version = "1.0", features = ["derive"], optional = true }
@@ -42,6 +43,10 @@ version-ranges = { version = "0.1.0", path = "version-ranges", features = ["prop
4243
[features]
4344
serde = ["dep:serde", "version-ranges/serde"]
4445

46+
[[bench]]
47+
name = "backtracking"
48+
harness = false
49+
4550
[[bench]]
4651
name = "large_case"
4752
harness = false

benches/backtracking.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
3+
//! This bench monitors the performance of backtracking and term intersection.
4+
//!
5+
//! Dependencies are constructed in a way that all versions need to be tested before
6+
//! pubgrub can determine that no solution exists.
7+
8+
use criterion::*;
9+
use pubgrub::OfflineDependencyProvider;
10+
use version_ranges::Ranges;
11+
12+
fn bench(c: &mut Criterion, case: &str, package_count: u32, version_count: u32) {
13+
let mut dependency_provider = OfflineDependencyProvider::<u32, Ranges<u32>>::new();
14+
let r = Ranges::strictly_lower_than(version_count);
15+
dependency_provider.add_dependencies(0u32, 0u32, [(1u32, r)]);
16+
17+
for n in 1..package_count {
18+
for v in 0..version_count {
19+
let r = Ranges::strictly_lower_than(v);
20+
dependency_provider.add_dependencies(n, v, [(n + 1, r)]);
21+
}
22+
}
23+
24+
c.bench_function(case, |b| {
25+
b.iter(|| {
26+
let _ = pubgrub::resolve(&dependency_provider, 0u32, 0u32);
27+
})
28+
});
29+
}
30+
31+
fn bench_group(c: &mut Criterion) {
32+
bench(c, "backtracking_small", 5, 60);
33+
bench(c, "backtracking_medium", 5, 200);
34+
bench(c, "backtracking_large", 5, 500);
35+
}
36+
37+
criterion_group!(benches, bench_group);
38+
criterion_main!(benches);

benches/large_case.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// SPDX-License-Identifier: MPL-2.0
2+
23
use std::time::Duration;
34

45
use criterion::*;

benches/sudoku.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ fn from_board(b: &str) -> Vec<(SudokuPackage, Range<Arc<usize>>)> {
5656
if let Some(val) = val.chars().next().unwrap().to_digit(10) {
5757
out.push((
5858
SudokuPackage::Cell {
59-
row: (row + 1).try_into().unwrap(),
60-
col: (col + 1).try_into().unwrap(),
59+
row: row + 1,
60+
col: col + 1,
6161
},
6262
Range::singleton(val as usize),
6363
));

test-examples/large_case_u16_NumberVersion.ron

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5521,4 +5521,4 @@
55215521
18: {},
55225522
19: {},
55235523
},
5524-
}
5524+
}

0 commit comments

Comments
 (0)