Skip to content

Commit

Permalink
feat: simplifying benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnarus-G committed May 2, 2023
1 parent d89280f commit 31e454c
Showing 1 changed file with 5 additions and 35 deletions.
40 changes: 5 additions & 35 deletions benches/bulk_renames.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::{path::PathBuf, str::FromStr};

use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use mrp::MatchAndReplacer;
use rename::{in_bulk, BulkRenameOptions};
use mrp::{MatchAndReplaceStrategy, MatchAndReplacer};

fn get_renamer() -> MatchAndReplacer<'static> {
let expr = mrp::parser::MatchAndReplaceExpression::from_str(
Expand Down Expand Up @@ -32,42 +31,13 @@ fn renaming_files(c: &mut Criterion) {

group.bench_with_input(BenchmarkId::from_parameter(size), &files, |b, files| {
b.iter(|| {
in_bulk(
&files,
&renamer,
&BulkRenameOptions {
no_rename: true,
multi: false,
},
)
files.iter().filter_map(|p| p.to_str()).for_each(|name| {
renamer.apply(name);
});
});
});
}
}

fn renaming_files_in_parallel(c: &mut Criterion) {
let renamer = get_renamer();
let mut group = c.benchmark_group("renames in parallel");
group.sample_size(10);

for size in [1000, 10000, 100000, 1000000].iter() {
let files = create_file_paths(*size);
group.throughput(criterion::Throughput::Elements(*size as u64));

group.bench_with_input(BenchmarkId::from_parameter(size), &files, |b, files| {
b.iter(|| {
in_bulk(
&files,
&renamer,
&BulkRenameOptions {
no_rename: true,
multi: true,
},
)
});
});
}
}

criterion_group!(benches, renaming_files, renaming_files_in_parallel);
criterion_group!(benches, renaming_files);
criterion_main!(benches);

0 comments on commit 31e454c

Please sign in to comment.