Skip to content
Closed
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions crates/criterion_compat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ keywords = ["codspeed", "benchmark", "criterion"]
criterion = { package = "codspeed-criterion-compat-walltime", path = "./criterion_fork", version = "=5.0.1", default-features = false }
codspeed = { path = "../codspeed", version = "=5.0.1" }
colored = "3.0.0"
clap = { version = "4", default-features = false, features = ["std"] }
clap = { version = "4", default-features = false, features = [
"std",
], optional = true }
regex = { version = "1.5", default-features = false, features = ["std"] }

futures = { version = "0.3", default-features = false, optional = true }
Expand All @@ -31,7 +33,9 @@ tokio = { version = "1.39", default-features = false, features = [
async-std = { version = "1.12", optional = true }

[features]
default = ["rayon", "plotters", "cargo_bench_support"]
default = ["cli", "rayon", "plotters", "cargo_bench_support"]
# Benchmark filtering from CLI arguments, which requires `clap`.
cli = ["dep:clap"]
# Criterion.rs features
async = ["futures", "criterion/async"]
async_futures = ["criterion/async_futures", "futures/executor", "async"]
Expand Down
8 changes: 7 additions & 1 deletion crates/criterion_compat/src/compat/criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use criterion::{
profiler::Profiler,
PlottingBackend,
};
#[cfg(feature = "cli")]
use regex::Regex;

use crate::{Bencher, BenchmarkFilter, BenchmarkGroup, BenchmarkId};
Expand All @@ -26,7 +27,6 @@ impl Criterion {
env!("CARGO_PKG_VERSION"),
);

// Parse CLI arguments to extract filter
let filter = Self::parse_filter();

Criterion {
Expand All @@ -38,6 +38,12 @@ impl Criterion {
}
}

#[cfg(not(feature = "cli"))]
fn parse_filter() -> BenchmarkFilter {
BenchmarkFilter::AcceptAll
}

#[cfg(feature = "cli")]
fn parse_filter() -> BenchmarkFilter {
use clap::{Arg, Command};

Expand Down
12 changes: 10 additions & 2 deletions crates/divan_compat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@ keywords = ["codspeed", "benchmark", "divan"]
codspeed = { path = "../codspeed", version = "=5.0.1" }
divan = { package = "codspeed-divan-compat-walltime", path = "./divan_fork", version = "=5.0.1" }
codspeed-divan-compat-macros = { version = "=5.0.1", path = './macros' }
regex = "1.11.3"
clap = { version = "4", default-features = false, features = ["std", "env"] }
regex = { version = "1.11.3", optional = true }
clap = { version = "4", default-features = false, features = [
"std",
"env",
], optional = true }

[features]
default = ["cli"]
# Benchmark filtering from CLI arguments, which requires `clap`.
cli = ["dep:clap", "dep:regex"]

[[bench]]
name = "basic_example"
Expand Down
7 changes: 7 additions & 0 deletions crates/divan_compat/src/compat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ pub mod __private {
}

mod bench;
#[cfg(feature = "cli")]
mod cli;
#[cfg(feature = "cli")]
mod config;
mod entry;
mod uri;
Expand Down Expand Up @@ -156,8 +158,10 @@ pub mod counter {
}
}
use codspeed::codspeed::CodSpeed;
#[cfg(feature = "cli")]
use config::Filter;
use entry::AnyBenchEntry;
#[cfg(feature = "cli")]
use regex::Regex;
use std::{cell::RefCell, rc::Rc};

Expand All @@ -184,6 +188,7 @@ pub fn main() {
// codspeed URI from entry metadata directly.

// 3. Filtering
#[cfg(feature = "cli")]
let should_run_benchmark_from_filters = {
let mut command = cli::command();
let matches = command.get_matches_mut();
Expand Down Expand Up @@ -215,6 +220,8 @@ pub fn main() {
}
}
};
#[cfg(not(feature = "cli"))]
let should_run_benchmark_from_filters = |_uri: &str| true;

// 4. Scan the tree and execute benchmarks
let codspeed = Rc::new(RefCell::new(CodSpeed::new()));
Expand Down
Loading