-
Notifications
You must be signed in to change notification settings - Fork 38
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
5 changed files
with
95 additions
and
4 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,85 @@ | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
//! This bench monitors the performance of backtracking and term intersection. | ||
//! | ||
//! Dependencies are constructed in a way that all versions need to be tested before finding a solution. | ||
use criterion::*; | ||
use pubgrub::OfflineDependencyProvider; | ||
use version_ranges::Ranges; | ||
|
||
fn backtracking_singletons(c: &mut Criterion, package_count: u32, version_count: u32) { | ||
let mut dependency_provider = OfflineDependencyProvider::<u32, Ranges<u32>>::new(); | ||
|
||
dependency_provider.add_dependencies(0u32, 0u32, [(1u32, Ranges::full())]); | ||
dependency_provider.add_dependencies(1u32, 0u32, []); | ||
|
||
for n in 1..package_count { | ||
for v in 1..version_count { | ||
dependency_provider.add_dependencies(n, v, [(n + 1, Ranges::singleton(v))]); | ||
} | ||
} | ||
|
||
c.bench_function("backtracking_singletons", |b| { | ||
b.iter(|| { | ||
let _ = pubgrub::resolve(&dependency_provider, 0u32, 0u32); | ||
}) | ||
}); | ||
} | ||
|
||
fn backtracking_disjoint_versions(c: &mut Criterion, package_count: u32, version_count: u32) { | ||
let mut dependency_provider = OfflineDependencyProvider::<u32, Ranges<u32>>::new(); | ||
|
||
let root_deps = [(1u32, Ranges::full()), (u32::MAX, Ranges::singleton(0u32))]; | ||
dependency_provider.add_dependencies(0u32, 0u32, root_deps); | ||
|
||
dependency_provider.add_dependencies(1u32, 0u32, []); | ||
|
||
for n in 1..package_count { | ||
for v in 1..version_count { | ||
dependency_provider.add_dependencies(n, v, [(n + 1, Ranges::singleton(v))]); | ||
} | ||
} | ||
for v in 1..version_count { | ||
dependency_provider.add_dependencies(package_count, v, [(u32::MAX, Ranges::singleton(v))]); | ||
} | ||
|
||
for v in 0..version_count { | ||
dependency_provider.add_dependencies(u32::MAX, v, []); | ||
} | ||
|
||
c.bench_function("backtracking_disjoint_versions", |b| { | ||
b.iter(|| { | ||
let _ = pubgrub::resolve(&dependency_provider, 0u32, 0u32); | ||
}) | ||
}); | ||
} | ||
|
||
fn backtracking_ranges(c: &mut Criterion, package_count: u32, version_count: u32) { | ||
let mut dependency_provider = OfflineDependencyProvider::<u32, Ranges<u32>>::new(); | ||
|
||
dependency_provider.add_dependencies(0u32, 0u32, [(1u32, Ranges::full())]); | ||
dependency_provider.add_dependencies(1u32, 0u32, []); | ||
|
||
for n in 1..package_count { | ||
for v in 1..version_count { | ||
let r = Ranges::higher_than(version_count - v); | ||
dependency_provider.add_dependencies(n, v, [(n + 1, r)]); | ||
} | ||
} | ||
|
||
c.bench_function("backtracking_ranges", |b| { | ||
b.iter(|| { | ||
let _ = pubgrub::resolve(&dependency_provider, 0u32, 0u32); | ||
}) | ||
}); | ||
} | ||
|
||
fn bench_group(c: &mut Criterion) { | ||
backtracking_singletons(c, 100, 500); | ||
backtracking_disjoint_versions(c, 300, 200); | ||
backtracking_ranges(c, 5, 200); | ||
} | ||
|
||
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::*; | ||
|
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 |
---|---|---|
|
@@ -5521,4 +5521,4 @@ | |
18: {}, | ||
19: {}, | ||
}, | ||
} | ||
} |