typos/benches/checks.rs

71 lines
2.2 KiB
Rust
Raw Normal View History

mod data;
use assert_fs::prelude::*;
2021-04-30 14:07:04 -04:00
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
2021-02-11 22:27:33 -05:00
use typos_cli::file::FileChecker;
2021-02-05 22:38:44 -05:00
fn bench_checks(c: &mut Criterion) {
let dict = typos_cli::dict::BuiltIn::new(Default::default());
let tokenizer = typos::tokens::Tokenizer::new();
let policy = typos_cli::policy::Policy::new()
.dict(&dict)
.tokenizer(&tokenizer);
2021-04-30 14:07:04 -04:00
let temp = assert_fs::TempDir::new().unwrap();
let mut group = c.benchmark_group("check_file");
2021-02-05 22:38:44 -05:00
for (name, sample) in data::DATA {
2021-04-30 14:07:04 -04:00
let sample_path = temp.child(name);
sample_path.write_str(sample).unwrap();
2021-02-05 22:38:44 -05:00
2021-04-30 14:07:04 -04:00
let len = sample.len();
group.throughput(Throughput::Bytes(len as u64));
group.bench_with_input(BenchmarkId::new("FoundFiles", name), &len, |b, _| {
2021-02-05 22:38:44 -05:00
b.iter(|| {
2021-02-11 22:27:33 -05:00
typos_cli::file::FoundFiles.check_file(
2021-02-05 22:38:44 -05:00
sample_path.path(),
true,
&policy,
2021-02-05 22:38:44 -05:00
&typos_cli::report::PrintSilent,
)
});
});
2021-04-30 14:07:04 -04:00
group.bench_with_input(BenchmarkId::new("Identifiers", name), &len, |b, _| {
2021-02-05 22:38:44 -05:00
b.iter(|| {
2021-02-11 22:27:33 -05:00
typos_cli::file::Identifiers.check_file(
2021-02-05 22:38:44 -05:00
sample_path.path(),
true,
&policy,
2021-02-05 22:38:44 -05:00
&typos_cli::report::PrintSilent,
)
});
});
2021-04-30 14:07:04 -04:00
group.bench_with_input(BenchmarkId::new("Words", name), &len, |b, _| {
2021-02-05 22:38:44 -05:00
b.iter(|| {
2021-02-11 22:27:33 -05:00
typos_cli::file::Words.check_file(
2021-02-05 22:38:44 -05:00
sample_path.path(),
true,
&policy,
2021-02-05 22:38:44 -05:00
&typos_cli::report::PrintSilent,
)
});
});
2021-04-30 14:07:04 -04:00
group.bench_with_input(BenchmarkId::new("Typos", name), &len, |b, _| {
2021-02-05 22:38:44 -05:00
b.iter(|| {
2021-02-11 22:27:33 -05:00
typos_cli::file::Typos.check_file(
2021-02-05 22:38:44 -05:00
sample_path.path(),
true,
&policy,
2021-02-05 22:38:44 -05:00
&typos_cli::report::PrintSilent,
)
});
});
}
group.finish();
2021-04-30 14:07:04 -04:00
temp.close().unwrap();
2021-02-05 22:38:44 -05:00
}
criterion_group!(benches, bench_checks,);
criterion_main!(benches);