diff options
author | Canop <cano.petrole@gmail.com> | 2021-03-25 18:51:18 +0100 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2021-03-25 18:51:18 +0100 |
commit | 1aed834b086f30db760ae2d1ea2d1aa89b595d50 (patch) | |
tree | 41b5ccdd468bb66b9353a461bbf33f2ac6d56f0c /benches | |
parent | 75ee6c28b082dd3e5ff095f1dcd053dbdc0fa972 (diff) |
replace criterion with glassbench for benchmarking
Diffstat (limited to 'benches')
-rw-r--r-- | benches/composite.rs | 22 | ||||
-rw-r--r-- | benches/fuzzy.rs | 18 | ||||
-rw-r--r-- | benches/path_normalization.rs | 16 |
3 files changed, 26 insertions, 30 deletions
diff --git a/benches/composite.rs b/benches/composite.rs index bde4505..77efb5d 100644 --- a/benches/composite.rs +++ b/benches/composite.rs @@ -5,34 +5,34 @@ use { command::CommandParts, pattern::*, }, - criterion::{black_box, criterion_group, criterion_main, Criterion}, + glassbench::*, }; // this file benches composite patterns on file names so don't // use file content sub patterns here static PATTERNS: &[&str] = &[ + "réveil", "r&!e", + "(!e&!b)|c", ]; -fn score_of_composite_benchmark(c: &mut Criterion) { +fn bench_score_of_composite(gb: &mut GlassBench) { let search_modes = SearchModeMap::default(); for pattern in PATTERNS { - let task = format!("Pattern({:?})::score_of", &pattern); - let parts = CommandParts::from(pattern.to_string()); - c.bench_function(&task, |b| { + let name = format!("Composite({:?})::score_of", &pattern); + gb.task(name, |b| { + let parts = CommandParts::from(pattern.to_string()); let cp = Pattern::new(&parts.pattern, &search_modes).unwrap(); b.iter(|| { for name in shared::NAMES { - black_box(cp.score_of_string(name)); + pretend_used(cp.score_of_string(name)); } }); }); } } -criterion_group!( - name = composite; - config = Criterion::default().without_plots(); - targets = score_of_composite_benchmark, +glassbench!( + "Composite Patterns", + bench_score_of_composite, ); -criterion_main!(composite); diff --git a/benches/fuzzy.rs b/benches/fuzzy.rs index 6f4ebcc..d635f99 100644 --- a/benches/fuzzy.rs +++ b/benches/fuzzy.rs @@ -2,28 +2,26 @@ mod shared; use { broot::pattern::FuzzyPattern, - criterion::{black_box, criterion_group, criterion_main, Criterion}, + glassbench::*, }; static PATTERNS: &[&str] = &["réveil", "AB", "e", "brt", "brootz"]; -fn score_of_benchmark(c: &mut Criterion) { +fn bench_score_of_fuzzy(gb: &mut GlassBench) { for pattern in PATTERNS { - let task = format!("FuzzyPattern({:?})::score_of", pattern); - c.bench_function(&task, |b| { + let task_name = format!("Fuzzy({:?})::score_of", pattern); + gb.task(task_name, |b| { let fp = FuzzyPattern::from(pattern); b.iter(|| { for name in shared::NAMES { - black_box(fp.score_of(name)); + pretend_used(fp.score_of(name)); } }); }); } } -criterion_group!( - name = fuzzy; - config = Criterion::default().without_plots(); - targets = score_of_benchmark, +glassbench!( + "Fuzzy Patterns", + bench_score_of_fuzzy, ); -criterion_main!(fuzzy); diff --git a/benches/path_normalization.rs b/benches/path_normalization.rs index a481684..8bdeb4c 100644 --- a/benches/path_normalization.rs +++ b/benches/path_normalization.rs @@ -1,6 +1,6 @@ use { broot::path, - criterion::{black_box, criterion_group, criterion_main, Criterion}, + glassbench::*, }; static PATHS: &[&str] = &[ @@ -20,19 +20,17 @@ static PATHS: &[&str] = &[ "π/2", ]; -fn normalization_benchmark(c: &mut Criterion) { - c.bench_function("normalize_path", |b| { +fn bench_normalization(gb: &mut GlassBench) { + gb.task("normalize_path", |b| { b.iter(|| { for path in PATHS { - black_box(path::normalize_path(path)); + pretend_used(path::normalize_path(path)); } }); }); } -criterion_group!( - name = path_normalization; - config = Criterion::default().without_plots(); - targets = normalization_benchmark, +glassbench!( + "Path Normalization", + bench_normalization, ); -criterion_main!(path_normalization); |