mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-22 17:11:07 -05:00
fce11d6c35
This is prep for experiments with getting this information ahead of time. See #224
40 lines
1.4 KiB
Rust
40 lines
1.4 KiB
Rust
mod data;
|
|
|
|
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
|
|
|
fn bench_tokenize(c: &mut Criterion) {
|
|
let mut group = c.benchmark_group("tokenize");
|
|
for (name, sample) in data::DATA {
|
|
let len = sample.len();
|
|
group.bench_with_input(BenchmarkId::new("ident(bytes)", name), &len, |b, _| {
|
|
let parser = typos::tokens::Tokenizer::new();
|
|
b.iter(|| parser.parse_bytes(sample.as_bytes()).last());
|
|
});
|
|
group.bench_with_input(BenchmarkId::new("ident(str)", name), &len, |b, _| {
|
|
let parser = typos::tokens::Tokenizer::new();
|
|
b.iter(|| parser.parse_str(sample).last());
|
|
});
|
|
group.bench_with_input(BenchmarkId::new("words", name), &len, |b, _| {
|
|
let symbol =
|
|
typos::tokens::Identifier::new_unchecked(sample, typos::tokens::Case::None, 0);
|
|
b.iter(|| symbol.split().last());
|
|
});
|
|
group.bench_with_input(
|
|
BenchmarkId::new("ident(bytes)+words", name),
|
|
&len,
|
|
|b, _| {
|
|
let parser = typos::tokens::Tokenizer::new();
|
|
b.iter(|| {
|
|
parser
|
|
.parse_bytes(sample.as_bytes())
|
|
.flat_map(|i| i.split())
|
|
.last()
|
|
});
|
|
},
|
|
);
|
|
}
|
|
group.finish();
|
|
}
|
|
|
|
criterion_group!(benches, bench_tokenize);
|
|
criterion_main!(benches);
|