2020-11-10 07:01:01 -05:00
|
|
|
mod data;
|
|
|
|
|
|
|
|
use assert_fs::prelude::*;
|
2021-02-05 22:38:44 -05:00
|
|
|
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
2021-02-11 22:27:33 -05:00
|
|
|
use typos_cli::file::FileChecker;
|
2020-11-10 07:01:01 -05:00
|
|
|
|
2021-02-05 22:38:44 -05:00
|
|
|
fn bench_checks(c: &mut Criterion) {
|
2021-03-01 21:37:05 -05:00
|
|
|
let dict = typos_cli::dict::BuiltIn::new(Default::default());
|
2021-02-12 19:43:12 -05:00
|
|
|
let tokenizer = typos::tokens::Tokenizer::new();
|
|
|
|
let policy = typos_cli::policy::Policy::new()
|
2021-03-01 21:37:05 -05:00
|
|
|
.dict(&dict)
|
2021-02-12 19:43:12 -05:00
|
|
|
.tokenizer(&tokenizer);
|
|
|
|
|
2021-02-05 22:38:44 -05:00
|
|
|
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();
|
|
|
|
|
|
|
|
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,
|
2021-02-12 19:43:12 -05:00
|
|
|
&policy,
|
2021-02-05 22:38:44 -05:00
|
|
|
&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();
|
|
|
|
|
|
|
|
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,
|
2021-02-12 19:43:12 -05:00
|
|
|
&policy,
|
2021-02-05 22:38:44 -05:00
|
|
|
&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();
|
|
|
|
|
|
|
|
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,
|
2021-02-12 19:43:12 -05:00
|
|
|
&policy,
|
2021-02-05 22:38:44 -05:00
|
|
|
&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();
|
|
|
|
|
|
|
|
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,
|
2021-02-12 19:43:12 -05:00
|
|
|
&policy,
|
2021-02-05 22:38:44 -05:00
|
|
|
&typos_cli::report::PrintSilent,
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
|
|
|
temp.close().unwrap();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
group.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(benches, bench_checks,);
|
|
|
|
criterion_main!(benches);
|