|
| 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); |
0 commit comments