Skip to content
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

feat: remove regex filter support to reduce compilation speed #15

Merged
merged 2 commits into from
Apr 29, 2024
Merged
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
39 changes: 0 additions & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ tinytemplate = "1.2"
cast = "0.3"
num-traits = { version = "0.2", default-features = false, features = ["std"] }
oorandom = "11.1"
regex = { version = "1.10", default-features = false, features = ["std"] }

# Optional dependencies
rayon = { version = "1.10", optional = true }
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ Criterion.<span></span>rs helps you write fast code by detecting and measuring p

## Reason for this fork

[criterion] is [passively-maintained](https://github.com/bheisler/criterion.rs/blob/f1ea31a92ff919a455f36b13c9a45fd74559d0fe/Cargo.toml#L63C27-L63C48) with outdated dependencies.
criterion is [passively-maintained](https://github.com/bheisler/criterion.rs/blob/f1ea31a92ff919a455f36b13c9a45fd74559d0fe/Cargo.toml#L63C27-L63C48) with outdated dependencies.

This is fork is updated with:

* renovate bot dependency update
* builtin [codspeed](https://codspeed.io) feature
* `clap` replaced with [`bpaf`](https://github.com/pacak/bpaf) to reduce binary size and compilation time
* merged the `criterion-plot` crate into `criterion2`
* remove regex filter support to reduce compilation speed

## Table of Contents

Expand Down
7 changes: 7 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env -S just --justfile

_default:
@just --list -u

watch command:
cargo watch -x '{{command}}'
29 changes: 3 additions & 26 deletions src/criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use std::path::{Path, PathBuf};
use std::sync::MutexGuard;
use std::time::Duration;

use regex::Regex;

use crate::bencher::Bencher;
use crate::benchmark_group::{BenchmarkGroup, BenchmarkId};
use crate::{
Expand Down Expand Up @@ -319,21 +317,6 @@ impl<M: Measurement> Criterion<M> {
self
}

#[must_use]
/// Filters the benchmarks. Only benchmarks with names that contain the
/// given string will be executed.
///
/// This overwrites [`Self::with_benchmark_filter`].
pub fn with_filter<S: Into<String>>(mut self, filter: S) -> Criterion<M> {
let filter_text = filter.into();
let filter = Regex::new(&filter_text).unwrap_or_else(|err| {
panic!("Unable to parse '{}' as a regular expression: {}", filter_text, err)
});
self.filter = BenchmarkFilter::Regex(filter);

self
}

/// Only run benchmarks specified by the given filter.
///
/// This overwrites [`Self::with_filter`].
Expand Down Expand Up @@ -441,14 +424,9 @@ 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())
} else {
let regex = Regex::new(filter).unwrap_or_else(|err| {
panic!("Unable to parse '{}' as a regular expression: {}", filter, err)
});
BenchmarkFilter::Regex(regex)
}
// if opts.exact {
BenchmarkFilter::Exact(filter.to_owned())
// }
} else {
BenchmarkFilter::AcceptAll
};
Expand Down Expand Up @@ -550,7 +528,6 @@ impl<M: Measurement> Criterion<M> {
pub(crate) fn filter_matches(&self, id: &str) -> bool {
match &self.filter {
BenchmarkFilter::AcceptAll => true,
BenchmarkFilter::Regex(regex) => regex.is_match(id),
BenchmarkFilter::Exact(exact) => id == exact,
BenchmarkFilter::RejectAll => false,
}
Expand Down
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#[cfg(all(feature = "rayon", target_arch = "wasm32"))]
compile_error!("Rayon cannot be used when targeting wasi32. Try disabling default features.");

use regex::Regex;

use serde::{Deserialize, Serialize};

// Needs to be declared before other modules
Expand Down Expand Up @@ -374,8 +372,6 @@ impl Default for ListFormat {
pub enum BenchmarkFilter {
/// Run all benchmarks.
AcceptAll,
/// Run benchmarks matching this regex.
Regex(Regex),
/// Run the benchmark matching this string exactly.
Exact(String),
/// Do not run any benchmarks.
Expand Down
5 changes: 3 additions & 2 deletions tests/criterion_tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#[cfg(feature = "plotters")]
use criterion2::SamplingMode;
use criterion2::{
criterion_group, criterion_main, profiler::Profiler, BatchSize, BenchmarkId, Criterion,
criterion_group, criterion_main, profiler::Profiler, BatchSize, BenchmarkFilter, BenchmarkId,
Criterion,
};
use serde_json::value::Value;
use std::cell::{Cell, RefCell};
Expand Down Expand Up @@ -254,7 +255,7 @@ fn test_filtering() {
let clone = counter.clone();

short_benchmark(&dir)
.with_filter("Foo")
.with_benchmark_filter(BenchmarkFilter::Exact("Foo".into()))
.bench_function("test_filtering", move |b| b.iter(|| clone.count()));

assert_eq!(counter.read(), 0);
Expand Down
Loading