Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion benches/sccache_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use divan::{Bencher, black_box};
use sccache::cache::{CacheRead, CacheWrite};
use sccache::lru_disk_cache::LruCache;
use sccache::util::{Digest, TimeMacroFinder, strip_basedirs};
use sccache::util::{Digest, TimeMacroFinder, strip_basedirs, strip_basedirs_from_arg};
use std::io::Cursor;

// =============================================================================
Expand Down Expand Up @@ -867,6 +867,43 @@ fn strip_basedirs_multiple(bencher: Bencher) {
bencher.bench(|| black_box(strip_basedirs(black_box(&output), black_box(&basedirs))));
}

/// Most dependency paths fall outside the configured checkout roots.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the 0 case returns immediately in the helper, so it only measures the loop —-worth keeping?

#[divan::bench(args = [0, 1, 8, 32])]
fn strip_basedirs_from_arg_mostly_unmatched(bencher: Bencher, root_count: usize) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the inputs here are bare paths, but this helper is about compiler arguments — could you please bench -I/path, -ffile-prefix-map=/path=/x too? that's where pathname_positions does the work.

let basedirs: Vec<Vec<u8>> = (0..root_count)
.map(|i| format!("/workspaces/project/checkouts/worktree-{i:02}/").into_bytes())
.collect();
let paths: Vec<Vec<u8>> = (0..100)
.map(|i| {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 7? please document or just use i / 10

if i % 10 == 0 {
let root = (i / 10 * 7) % root_count.max(1);
format!("/workspaces/project/checkouts/worktree-{root:02}/src/lib.rs")
} else {
format!("/Users/example/.cargo/registry/src/package-{i}/src/lib.rs")
}
.into_bytes()
})
.collect();

for (i, path) in paths.iter().enumerate() {
let expected = if root_count > 0 && i % 10 == 0 {
b"src/lib.rs".as_slice()
} else {
path.as_slice()
};
assert_eq!(strip_basedirs_from_arg(path, &basedirs), expected);
}

bencher.bench(|| {
for path in &paths {
black_box(strip_basedirs_from_arg(
black_box(path),
black_box(&basedirs),
));
}
});
}

fn main() {
divan::main();
}