-
Notifications
You must be signed in to change notification settings - Fork 752
bench: measure basedir stripping from compiler arguments #2838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
||
| // ============================================================================= | ||
|
|
@@ -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. | ||
| #[divan::bench(args = [0, 1, 8, 32])] | ||
| fn strip_basedirs_from_arg_mostly_unmatched(bencher: Bencher, root_count: usize) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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| { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
| } | ||
There was a problem hiding this comment.
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?