2024-08-06 21:55:20 +03:00
|
|
|
use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput};
|
2024-08-11 12:36:07 +03:00
|
|
|
use gitbutler_branch_actions::{get_branch_listing_details, list_branches};
|
2024-08-06 21:55:20 +03:00
|
|
|
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);
|
2024-08-07 11:51:46 +03:00
|
|
|
let ctx = CommandContext::open(&project).unwrap();
|
2024-08-06 21:55:20 +03:00
|
|
|
group.throughput(Throughput::Elements(num_references));
|
|
|
|
group
|
|
|
|
.bench_function("no filter", |b| {
|
2024-08-07 11:51:46 +03:00
|
|
|
b.iter(|| list_branches(black_box(&ctx), None, None))
|
2024-08-06 21:55:20 +03:00
|
|
|
})
|
|
|
|
.bench_function("name-filter rejecting all", |b| {
|
2024-08-09 22:12:57 +03:00
|
|
|
b.iter(|| list_branches(black_box(&ctx), None, Some(vec!["not-available".into()])))
|
2024-08-06 21:55:20 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-11 12:36:07 +03:00
|
|
|
pub fn benchmark_branch_details(c: &mut Criterion) {
|
|
|
|
for (bench_name, (repo_name, branch_name, files_to_diff, script_name)) in [
|
|
|
|
(
|
|
|
|
"branch-details [many branches no change]",
|
|
|
|
("many-local", "virtual", 0, "branch-benches.sh"),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"branch-details [tiny no change]",
|
|
|
|
(
|
|
|
|
"one-vbranch-on-integration-two-remotes",
|
|
|
|
"main",
|
|
|
|
0,
|
|
|
|
"for-listing.sh",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"branch-details [big repo no change]",
|
|
|
|
(
|
|
|
|
"big-repo-clone",
|
|
|
|
"no-change",
|
|
|
|
0,
|
|
|
|
"branch-details-benches.sh",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"branch-details [every-file-changed]",
|
|
|
|
(
|
|
|
|
"big-repo-clone-one-commit-ahead",
|
|
|
|
"change-with-new-content",
|
|
|
|
10_000,
|
|
|
|
"branch-details-benches.sh",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
] {
|
|
|
|
let mut group = c.benchmark_group(bench_name);
|
|
|
|
let project = fixture_project(repo_name, script_name);
|
|
|
|
if files_to_diff != 0 {
|
|
|
|
group.throughput(Throughput::Elements(files_to_diff));
|
|
|
|
}
|
|
|
|
group.bench_function("list details of known branch", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
let ctx = CommandContext::open(&project).unwrap();
|
|
|
|
let details =
|
|
|
|
get_branch_listing_details(black_box(&ctx), Some(branch_name)).unwrap();
|
|
|
|
assert_eq!(details.len(), 1, "{script_name}:{repo_name}:{branch_name}");
|
|
|
|
assert_eq!(
|
|
|
|
details[0].number_of_files, files_to_diff as usize,
|
|
|
|
"currently it creates a new vbranch for changes in local-commits, something we leverage here"
|
|
|
|
);
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
2024-08-12 12:11:22 +03:00
|
|
|
|
|
|
|
let mut group = c.benchmark_group("branch-details [revwalk]");
|
|
|
|
let project = fixture_project("revwalk-repo", "branch-details-benches.sh");
|
|
|
|
group.throughput(Throughput::Elements(100 + 15 + 50));
|
|
|
|
group.bench_function("count commits/collect authors", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
let ctx = CommandContext::open(&project).unwrap();
|
|
|
|
let details = get_branch_listing_details(
|
|
|
|
black_box(&ctx),
|
|
|
|
["feature", "main", "non-virtual-feature"],
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(details.len(), 3);
|
|
|
|
})
|
|
|
|
});
|
2024-08-11 12:36:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(benches, benchmark_list_branches, benchmark_branch_details);
|
2024-08-06 21:55:20 +03:00
|
|
|
criterion_main!(benches);
|