Skip to content

Commit

Permalink
Add benchmark whitelist flag
Browse files Browse the repository at this point in the history
  • Loading branch information
toluschr committed Oct 20, 2024
1 parent b6f91be commit 9db239f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Display for Error {
}

/// Find all benchmarks recursively in the specified location.
pub fn find_benchmarks(paths: &[PathBuf]) -> Vec<BenchmarkLoader> {
pub fn find_benchmarks(paths: &[PathBuf], names: &Vec<String>) -> Vec<BenchmarkLoader> {
let mut benchmarks: HashMap<String, (Option<PathBuf>, Option<PathBuf>)> = HashMap::new();

for path in paths {
Expand All @@ -47,11 +47,14 @@ pub fn find_benchmarks(paths: &[PathBuf]) -> Vec<BenchmarkLoader> {

if let Some(name) = path.parent().and_then(|path| path.file_name()) {
let name = name.to_string_lossy().to_string();
let bench = benchmarks.entry(name).or_default();
match file_name.as_str() {
"setup" => bench.0 = Some(path),
"benchmark" => bench.1 = Some(path),
_ => unreachable!(),

if names.len() == 0 || names.contains(&name) {
let bench = benchmarks.entry(name).or_default();
match file_name.as_str() {
"setup" => bench.0 = Some(path),
"benchmark" => bench.1 = Some(path),
_ => unreachable!(),
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! CLI argument parsing.
use std::path::PathBuf;
use std::string::String;

use clap::Parser;

Expand All @@ -15,6 +16,10 @@ pub struct Config {
#[clap(short, long, value_name = "DIRECTORY", default_value = "./benchmarks")]
pub benchmarks: Vec<PathBuf>,

/// Benchmark name.
#[clap(short, long, value_name = "WHITELIST")]
pub whitelist: Vec<String>,

/// Number of warmup iterations.
#[clap(long, value_name = "NUM", default_value = "1")]
pub warmup: usize,
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
let config = Config::parse();

// Find all available benchmarks.
let mut loaders = bench::find_benchmarks(&config.benchmarks);
let mut loaders = bench::find_benchmarks(&config.benchmarks, &config.whitelist);

// Run all benchmarks one at a time.
let results: Vec<Results> = loaders
Expand Down

0 comments on commit 9db239f

Please sign in to comment.