mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-20 16:11:46 +03:00
60 lines
2.1 KiB
Rust
60 lines
2.1 KiB
Rust
|
use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput};
|
||
|
use gitbutler_branch_actions::list_branches;
|
||
|
use gitbutler_command_context::CommandContext;
|
||
|
use gitbutler_project::Project;
|
||
|
|
||
|
pub fn fixture_project(name: &str, script: &str) -> Project {
|
||
|
gitbutler_testsupport::read_only::fixture_project(script, name).unwrap()
|
||
|
}
|
||
|
|
||
|
pub fn benchmark_list_branches(c: &mut Criterion) {
|
||
|
const NUM_BRANCHES: u64 = 300;
|
||
|
for (bench_name, num_references, (repo_name, script_name)) in [
|
||
|
(
|
||
|
"list-branches[many local branches]",
|
||
|
NUM_BRANCHES,
|
||
|
("many-local", "branch-benches.sh"),
|
||
|
),
|
||
|
(
|
||
|
"list-branches[tiny repo]",
|
||
|
3,
|
||
|
("one-vbranch-on-integration-two-remotes", "for-listing.sh"),
|
||
|
),
|
||
|
(
|
||
|
"list-branches[many local branches [packed]]",
|
||
|
NUM_BRANCHES,
|
||
|
("many-local-packed", "branch-benches.sh"),
|
||
|
),
|
||
|
(
|
||
|
"list-branches[many local branches [tracked]]",
|
||
|
NUM_BRANCHES * 2,
|
||
|
("many-local-tracked", "branch-benches.sh"),
|
||
|
),
|
||
|
(
|
||
|
"list-branches[many local branches [tracked & packed]]",
|
||
|
NUM_BRANCHES * 2,
|
||
|
("many-local-tracked-packed", "branch-benches.sh"),
|
||
|
),
|
||
|
] {
|
||
|
let mut group = c.benchmark_group(bench_name);
|
||
|
let project = fixture_project(repo_name, script_name);
|
||
|
group.throughput(Throughput::Elements(num_references));
|
||
|
group
|
||
|
.bench_function("no filter", |b| {
|
||
|
b.iter(|| {
|
||
|
let ctx = CommandContext::open(&project).unwrap();
|
||
|
list_branches(black_box(&ctx), None, None)
|
||
|
})
|
||
|
})
|
||
|
.bench_function("name-filter rejecting all", |b| {
|
||
|
b.iter(|| {
|
||
|
let ctx = CommandContext::open(&project).unwrap();
|
||
|
list_branches(black_box(&ctx), None, Some(vec!["not available".into()]))
|
||
|
})
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
criterion_group!(benches, benchmark_list_branches);
|
||
|
criterion_main!(benches);
|