2020-11-10 07:01:01 -05:00
|
|
|
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;
|
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-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,
|
2021-02-12 19:43:12 -05:00
|
|
|
&policy,
|
2021-05-04 22:54:25 -04:00
|
|
|
&PrintSilent,
|
2021-02-05 22:38:44 -05:00
|
|
|
)
|
|
|
|
});
|
|
|
|
});
|
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,
|
2021-02-12 19:43:12 -05:00
|
|
|
&policy,
|
2021-05-04 22:54:25 -04:00
|
|
|
&PrintSilent,
|
2021-02-05 22:38:44 -05:00
|
|
|
)
|
|
|
|
});
|
|
|
|
});
|
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-05-04 22:54:25 -04:00
|
|
|
typos_cli::file::Words.check_file(sample_path.path(), true, &policy, &PrintSilent)
|
2021-02-05 22:38:44 -05:00
|
|
|
});
|
|
|
|
});
|
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-05-04 22:54:25 -04:00
|
|
|
typos_cli::file::Typos.check_file(sample_path.path(), true, &policy, &PrintSilent)
|
2021-02-05 22:38:44 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
group.finish();
|
2021-04-30 14:07:04 -04:00
|
|
|
|
|
|
|
temp.close().unwrap();
|
2021-02-05 22:38:44 -05:00
|
|
|
}
|
|
|
|
|
2021-05-04 22:54:25 -04:00
|
|
|
#[derive(Debug, Default)]
|
|
|
|
pub struct PrintSilent;
|
|
|
|
|
|
|
|
impl typos_cli::report::Report for PrintSilent {
|
|
|
|
fn report(&self, _msg: typos_cli::report::Message) -> Result<(), std::io::Error> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-05 22:38:44 -05:00
|
|
|
criterion_group!(benches, bench_checks,);
|
|
|
|
criterion_main!(benches);
|