Skip to content

Commit f182411

Browse files
committed
add a bench for workspace initialization
1 parent 42962da commit f182411

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

benches/benchsuite/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ description = "Benchmarking suite for Cargo."
1010

1111
[dependencies]
1212
cargo = { path = "../.." }
13+
cargo-test-support = { path = "../../crates/cargo-test-support" }
1314
# Consider removing html_reports in 0.4 and switching to `cargo criterion`.
1415
criterion = { version = "0.3.5", features = ["html_reports"] }
1516
flate2 = { version = "1.0.3", default-features = false, features = ["zlib"] }
@@ -22,3 +23,7 @@ bench = false
2223
[[bench]]
2324
name = "resolve"
2425
harness = false
26+
27+
[[bench]]
28+
name = "workspace_initialization"
29+
harness = false
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use benchsuite::fixtures;
2+
use cargo::core::Workspace;
3+
use criterion::{criterion_group, criterion_main, Criterion};
4+
5+
fn workspace_initialization(c: &mut Criterion) {
6+
let fixtures = fixtures!();
7+
let mut group = c.benchmark_group("workspace_initialization");
8+
for (ws_name, ws_root) in fixtures.workspaces() {
9+
let config = fixtures.make_config(&ws_root);
10+
// The resolver info is initialized only once in a lazy fashion. This
11+
// allows criterion to skip this workspace if the user passes a filter
12+
// on the command-line (like `cargo bench -- workspace_initialization/tikv`).
13+
group.bench_function(ws_name, |b| {
14+
b.iter(|| Workspace::new(&ws_root.join("Cargo.toml"), &config).unwrap())
15+
});
16+
}
17+
group.finish();
18+
}
19+
20+
// Criterion complains about the measurement time being too small, but the
21+
// measurement time doesn't seem important to me, what is more important is
22+
// the number of iterations which defaults to 100, which seems like a
23+
// reasonable default. Otherwise, the measurement time would need to be
24+
// changed per workspace. We wouldn't want to spend 60s on every workspace,
25+
// that would take too long and isn't necessary for the smaller workspaces.
26+
criterion_group!(benches, workspace_initialization);
27+
criterion_main!(benches);
44.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)