-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
49,241 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
use std::collections::BTreeMap; | ||
use std::time::Duration; | ||
|
||
use criterion::*; | ||
use pubgrub::OfflineDependencyProvider; | ||
use version_ranges::Ranges; | ||
|
||
type Deps = BTreeMap<u32, BTreeMap<u8, BTreeMap<u32, Vec<(u8, u8)>>>>; | ||
|
||
fn bench(b: &mut Bencher, data: &str) { | ||
let dependencies = ron::de::from_str::<Deps>(data).unwrap(); | ||
|
||
let mut dependency_provider = OfflineDependencyProvider::<u32, Ranges<u8>>::new(); | ||
|
||
for (&p, vmap) in &dependencies { | ||
for (&v, dmap) in vmap { | ||
let deps_iter = dmap.iter().map(|(&d, intervals)| { | ||
let mut r = Ranges::empty(); | ||
for &(start, end) in intervals { | ||
r = r.r#union(&Ranges::from_range_bounds(start..=end)); | ||
} | ||
(d, r) | ||
}); | ||
dependency_provider.add_dependencies(p, v, deps_iter); | ||
} | ||
} | ||
|
||
if let Some((p, v)) = dependencies | ||
.first_key_value() | ||
.and_then(|(&p, vmap)| vmap.first_key_value().map(|(&v, _)| (p, v))) | ||
{ | ||
b.iter(|| { | ||
let _ = pubgrub::resolve(&dependency_provider, p, v); | ||
}); | ||
} | ||
} | ||
|
||
fn bench_group(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("bench"); | ||
group.measurement_time(Duration::from_secs(20)); | ||
|
||
for case in ["small", "medium", "large"] { | ||
let name = format!("backtracking_{case}"); | ||
let data = std::fs::read_to_string(format!("test-examples/{name}.ron")).unwrap(); | ||
group.bench_function(name, |b| { | ||
bench(b, &data); | ||
}); | ||
} | ||
|
||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, bench_group); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
use std::time::Duration; | ||
|
||
use criterion::*; | ||
|
Oops, something went wrong.