Skip to content

Commit

Permalink
Make filters to look for a substring unless exact is given (#65)
Browse files Browse the repository at this point in the history
eecce42 removed partial filter matches to improve compilation speed, but
we can still do something similar without using regex crate by looking
for a substring. Plus I'd get regex back and put it behind a feature
flag, those who care - can keep using it.
  • Loading branch information
pacak authored Oct 31, 2024
1 parent 156a8d3 commit 3ae0469
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,12 @@ impl<M: Measurement> Criterion<M> {
// --ignored overwrites any name-based filters passed in.
BenchmarkFilter::RejectAll
} else if let Some(filter) = opts.filter.as_ref() {
// if opts.exact {
BenchmarkFilter::Exact(filter.to_owned())
// }
let filter = filter.to_owned();
if opts.exact {
BenchmarkFilter::Exact(filter)
} else {
BenchmarkFilter::Substring(filter)
}
} else {
BenchmarkFilter::AcceptAll
};
Expand Down Expand Up @@ -475,6 +478,7 @@ impl<M: Measurement> Criterion<M> {
BenchmarkFilter::AcceptAll => true,
BenchmarkFilter::Exact(exact) => id == exact,
BenchmarkFilter::RejectAll => false,
BenchmarkFilter::Substring(s) => id.contains(s),
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ pub enum BenchmarkFilter {
AcceptAll,
/// Run the benchmark matching this string exactly.
Exact(String),
/// Look for benchmark that contain substring
Substring(String),
/// Do not run any benchmarks.
RejectAll,
}
Expand Down

0 comments on commit 3ae0469

Please sign in to comment.