Skip to content

Add support for comma-separated include/exclude filters to runtime benchmarks #1471

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

Merged
merged 1 commit into from
Oct 19, 2022
Merged
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
51 changes: 47 additions & 4 deletions collector/benchlib/src/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,17 @@ macro_rules! define_benchmark {

pub use define_benchmark;

/// Tests if the name of the benchmark passes through the include and exclude filter flags.
/// Tests if the name of the benchmark passes through the include and exclude filters.
/// Both filters can contain multiple comma-separated prefixes.
pub fn passes_filter(name: &str, exclude: Option<&str>, include: Option<&str>) -> bool {
match (exclude, include) {
(Some(exclude), Some(include)) => name.starts_with(include) && !name.starts_with(exclude),
(None, Some(include)) => name.starts_with(include),
(Some(exclude), None) => !name.starts_with(&exclude),
(Some(exclude), Some(include)) => {
let included = include.split(",").any(|filter| name.starts_with(filter));
let excluded = exclude.split(",").any(|filter| name.starts_with(filter));
included && !excluded
}
(None, Some(include)) => include.split(",").any(|filter| name.starts_with(filter)),
(Some(exclude), None) => !exclude.split(",").any(|filter| name.starts_with(filter)),
(None, None) => true,
}
}
Expand All @@ -137,3 +142,41 @@ pub fn black_box<T>(dummy: T) -> T {
ret
}
}

#[cfg(test)]
mod tests {
use crate::benchmark::passes_filter;

#[test]
fn test_passes_filter_no_filter() {
assert!(passes_filter("foo", None, None));
}

#[test]
fn test_passes_filter_include() {
assert!(!passes_filter("foo", None, Some("bar")));
assert!(!passes_filter("foo", None, Some("foobar")));

assert!(passes_filter("foo", None, Some("f")));
assert!(passes_filter("foo", None, Some("foo")));
assert!(passes_filter("foo", None, Some("bar,baz,foo")));
}

#[test]
fn test_passes_filter_exclude() {
assert!(passes_filter("foo", Some("bar"), None));
assert!(passes_filter("foo", Some("foobar"), None));

assert!(!passes_filter("foo", Some("f"), None));
assert!(!passes_filter("foo", Some("foo"), None));
assert!(!passes_filter("foo", Some("bar,baz,foo"), None));
}

#[test]
fn test_passes_filter_include_exclude() {
assert!(!passes_filter("foo", Some("bar"), Some("baz")));
assert!(passes_filter("foo", Some("bar"), Some("foo")));
assert!(!passes_filter("foo", Some("foo"), Some("bar")));
assert!(!passes_filter("foo", Some("foo"), Some("foo")));
}
}