mirror of
https://github.com/crate-ci/typos.git
synced 2024-12-26 01:22:08 -05:00
style(bench): Modernize checks bench
This commit is contained in:
parent
e4f477799a
commit
c2e398975a
1 changed files with 15 additions and 31 deletions
|
@ -1,7 +1,7 @@
|
|||
mod data;
|
||||
|
||||
use assert_fs::prelude::*;
|
||||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
||||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
|
||||
use typos_cli::file::FileChecker;
|
||||
|
||||
fn bench_checks(c: &mut Criterion) {
|
||||
|
@ -11,14 +11,16 @@ fn bench_checks(c: &mut Criterion) {
|
|||
.dict(&dict)
|
||||
.tokenizer(&tokenizer);
|
||||
|
||||
let mut group = c.benchmark_group("checks");
|
||||
for (name, sample) in data::DATA {
|
||||
let len = sample.len();
|
||||
group.bench_with_input(BenchmarkId::new("files", name), &len, |b, _| {
|
||||
let temp = assert_fs::TempDir::new().unwrap();
|
||||
let sample_path = temp.child("sample");
|
||||
sample_path.write_str(sample).unwrap();
|
||||
let temp = assert_fs::TempDir::new().unwrap();
|
||||
|
||||
let mut group = c.benchmark_group("check_file");
|
||||
for (name, sample) in data::DATA {
|
||||
let sample_path = temp.child(name);
|
||||
sample_path.write_str(sample).unwrap();
|
||||
|
||||
let len = sample.len();
|
||||
group.throughput(Throughput::Bytes(len as u64));
|
||||
group.bench_with_input(BenchmarkId::new("FoundFiles", name), &len, |b, _| {
|
||||
b.iter(|| {
|
||||
typos_cli::file::FoundFiles.check_file(
|
||||
sample_path.path(),
|
||||
|
@ -27,14 +29,8 @@ fn bench_checks(c: &mut Criterion) {
|
|||
&typos_cli::report::PrintSilent,
|
||||
)
|
||||
});
|
||||
|
||||
temp.close().unwrap();
|
||||
});
|
||||
group.bench_with_input(BenchmarkId::new("identifiers", name), &len, |b, _| {
|
||||
let temp = assert_fs::TempDir::new().unwrap();
|
||||
let sample_path = temp.child("sample");
|
||||
sample_path.write_str(sample).unwrap();
|
||||
|
||||
group.bench_with_input(BenchmarkId::new("Identifiers", name), &len, |b, _| {
|
||||
b.iter(|| {
|
||||
typos_cli::file::Identifiers.check_file(
|
||||
sample_path.path(),
|
||||
|
@ -43,14 +39,8 @@ fn bench_checks(c: &mut Criterion) {
|
|||
&typos_cli::report::PrintSilent,
|
||||
)
|
||||
});
|
||||
|
||||
temp.close().unwrap();
|
||||
});
|
||||
group.bench_with_input(BenchmarkId::new("words", name), &len, |b, _| {
|
||||
let temp = assert_fs::TempDir::new().unwrap();
|
||||
let sample_path = temp.child("sample");
|
||||
sample_path.write_str(sample).unwrap();
|
||||
|
||||
group.bench_with_input(BenchmarkId::new("Words", name), &len, |b, _| {
|
||||
b.iter(|| {
|
||||
typos_cli::file::Words.check_file(
|
||||
sample_path.path(),
|
||||
|
@ -59,14 +49,8 @@ fn bench_checks(c: &mut Criterion) {
|
|||
&typos_cli::report::PrintSilent,
|
||||
)
|
||||
});
|
||||
|
||||
temp.close().unwrap();
|
||||
});
|
||||
group.bench_with_input(BenchmarkId::new("typos", name), &len, |b, _| {
|
||||
let temp = assert_fs::TempDir::new().unwrap();
|
||||
let sample_path = temp.child("sample");
|
||||
sample_path.write_str(sample).unwrap();
|
||||
|
||||
group.bench_with_input(BenchmarkId::new("Typos", name), &len, |b, _| {
|
||||
b.iter(|| {
|
||||
typos_cli::file::Typos.check_file(
|
||||
sample_path.path(),
|
||||
|
@ -75,11 +59,11 @@ fn bench_checks(c: &mut Criterion) {
|
|||
&typos_cli::report::PrintSilent,
|
||||
)
|
||||
});
|
||||
|
||||
temp.close().unwrap();
|
||||
});
|
||||
}
|
||||
group.finish();
|
||||
|
||||
temp.close().unwrap();
|
||||
}
|
||||
|
||||
criterion_group!(benches, bench_checks,);
|
||||
|
|
Loading…
Reference in a new issue