Skip to content

Commit

Permalink
Support running benchmarks with --exact.
Browse files Browse the repository at this point in the history
Required by cargo-nextest.
  • Loading branch information
sunshowers committed Sep 10, 2022
1 parent 8a0a7b3 commit c929ff3
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ pub enum BenchmarkFilter {
AcceptAll,
/// Run benchmarks matching this regex.
Regex(Regex),
/// Run the benchmark matching this string exactly.
Exact(String),
/// Do not run any benchmarks.
RejectAll,
}
Expand Down Expand Up @@ -821,6 +823,9 @@ impl<M: Measurement> Criterion<M> {
.arg(Arg::new("ignored")
.long("ignored")
.help("List or run ignored benchmarks (currently means skip all benchmarks)"))
.arg(Arg::new("exact")
.long("exact")
.help("Run benchmarks that exactly match the provided filter"))
.arg(Arg::new("profile-time")
.long("profile-time")
.takes_value(true)
Expand Down Expand Up @@ -988,13 +993,17 @@ https://bheisler.github.io/criterion.rs/book/faq.html
// --ignored overwrites any name-based filters passed in.
BenchmarkFilter::RejectAll
} else if let Some(filter) = matches.value_of("FILTER") {
let regex = Regex::new(filter).unwrap_or_else(|err| {
panic!(
"Unable to parse '{}' as a regular expression: {}",
filter, err
)
});
BenchmarkFilter::Regex(regex)
if matches.is_present("exact") {
BenchmarkFilter::Exact(filter.to_owned())
} else {
let regex = Regex::new(filter).unwrap_or_else(|err| {
panic!(
"Unable to parse '{}' as a regular expression: {}",
filter, err
)
});
BenchmarkFilter::Regex(regex)
}
} else {
BenchmarkFilter::AcceptAll
};
Expand Down Expand Up @@ -1136,6 +1145,7 @@ https://bheisler.github.io/criterion.rs/book/faq.html
match &self.filter {
BenchmarkFilter::AcceptAll => true,
BenchmarkFilter::Regex(regex) => regex.is_match(id),
BenchmarkFilter::Exact(exact) => id == exact,
BenchmarkFilter::RejectAll => false,
}
}
Expand Down

0 comments on commit c929ff3

Please sign in to comment.