-
Notifications
You must be signed in to change notification settings - Fork 83
/
checks.rs
69 lines (60 loc) · 2.17 KB
/
checks.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
mod data;
use assert_fs::prelude::*;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use typos_cli::file::FileChecker;
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);
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(),
true,
&policy,
&PrintSilent,
)
});
});
group.bench_with_input(BenchmarkId::new("Identifiers", name), &len, |b, _| {
b.iter(|| {
typos_cli::file::Identifiers.check_file(
sample_path.path(),
true,
&policy,
&PrintSilent,
)
});
});
group.bench_with_input(BenchmarkId::new("Words", name), &len, |b, _| {
b.iter(|| {
typos_cli::file::Words.check_file(sample_path.path(), true, &policy, &PrintSilent)
});
});
group.bench_with_input(BenchmarkId::new("Typos", name), &len, |b, _| {
b.iter(|| {
typos_cli::file::Typos.check_file(sample_path.path(), true, &policy, &PrintSilent)
});
});
}
group.finish();
temp.close().unwrap();
}
#[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(())
}
}
criterion_group!(benches, bench_checks,);
criterion_main!(benches);