mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-24 18:10:56 -05:00
Merge pull request #236 from epage/clean
style(bench): Modernize checks bench
This commit is contained in:
commit
af1324fa37
1 changed files with 15 additions and 31 deletions
|
@ -1,7 +1,7 @@
|
||||||
mod data;
|
mod data;
|
||||||
|
|
||||||
use assert_fs::prelude::*;
|
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;
|
use typos_cli::file::FileChecker;
|
||||||
|
|
||||||
fn bench_checks(c: &mut Criterion) {
|
fn bench_checks(c: &mut Criterion) {
|
||||||
|
@ -11,14 +11,16 @@ fn bench_checks(c: &mut Criterion) {
|
||||||
.dict(&dict)
|
.dict(&dict)
|
||||||
.tokenizer(&tokenizer);
|
.tokenizer(&tokenizer);
|
||||||
|
|
||||||
let mut group = c.benchmark_group("checks");
|
let temp = assert_fs::TempDir::new().unwrap();
|
||||||
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 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(|| {
|
b.iter(|| {
|
||||||
typos_cli::file::FoundFiles.check_file(
|
typos_cli::file::FoundFiles.check_file(
|
||||||
sample_path.path(),
|
sample_path.path(),
|
||||||
|
@ -27,14 +29,8 @@ fn bench_checks(c: &mut Criterion) {
|
||||||
&typos_cli::report::PrintSilent,
|
&typos_cli::report::PrintSilent,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
temp.close().unwrap();
|
|
||||||
});
|
});
|
||||||
group.bench_with_input(BenchmarkId::new("identifiers", name), &len, |b, _| {
|
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();
|
|
||||||
|
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
typos_cli::file::Identifiers.check_file(
|
typos_cli::file::Identifiers.check_file(
|
||||||
sample_path.path(),
|
sample_path.path(),
|
||||||
|
@ -43,14 +39,8 @@ fn bench_checks(c: &mut Criterion) {
|
||||||
&typos_cli::report::PrintSilent,
|
&typos_cli::report::PrintSilent,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
temp.close().unwrap();
|
|
||||||
});
|
});
|
||||||
group.bench_with_input(BenchmarkId::new("words", name), &len, |b, _| {
|
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();
|
|
||||||
|
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
typos_cli::file::Words.check_file(
|
typos_cli::file::Words.check_file(
|
||||||
sample_path.path(),
|
sample_path.path(),
|
||||||
|
@ -59,14 +49,8 @@ fn bench_checks(c: &mut Criterion) {
|
||||||
&typos_cli::report::PrintSilent,
|
&typos_cli::report::PrintSilent,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
temp.close().unwrap();
|
|
||||||
});
|
});
|
||||||
group.bench_with_input(BenchmarkId::new("typos", name), &len, |b, _| {
|
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();
|
|
||||||
|
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
typos_cli::file::Typos.check_file(
|
typos_cli::file::Typos.check_file(
|
||||||
sample_path.path(),
|
sample_path.path(),
|
||||||
|
@ -75,11 +59,11 @@ fn bench_checks(c: &mut Criterion) {
|
||||||
&typos_cli::report::PrintSilent,
|
&typos_cli::report::PrintSilent,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
temp.close().unwrap();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
group.finish();
|
group.finish();
|
||||||
|
|
||||||
|
temp.close().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
criterion_group!(benches, bench_checks,);
|
criterion_group!(benches, bench_checks,);
|
||||||
|
|
Loading…
Reference in a new issue