typos/benches/tokenize.rs

41 lines
1.4 KiB
Rust
Raw Normal View History

2019-01-22 17:01:33 -05:00
mod data;
2021-02-05 22:38:44 -05:00
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();
2021-04-21 13:12:59 -04:00
group.bench_with_input(BenchmarkId::new("ident(bytes)", name), &len, |b, _| {
2021-02-05 22:38:44 -05:00
let parser = typos::tokens::Tokenizer::new();
b.iter(|| parser.parse_bytes(sample.as_bytes()).last());
});
2021-04-21 13:12:59 -04:00
group.bench_with_input(BenchmarkId::new("ident(str)", name), &len, |b, _| {
let parser = typos::tokens::Tokenizer::new();
b.iter(|| parser.parse_str(sample).last());
});
2021-02-05 22:38:44 -05:00
group.bench_with_input(BenchmarkId::new("words", name), &len, |b, _| {
let symbol =
typos::tokens::Identifier::new_unchecked(sample, typos::tokens::Case::None, 0);
2021-02-05 22:38:44 -05:00
b.iter(|| symbol.split().last());
});
2021-04-21 13:12:59 -04:00
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()
});
},
);
2021-02-05 22:38:44 -05:00
}
group.finish();
}
criterion_group!(benches, bench_tokenize);
criterion_main!(benches);