typos/benches/corrections.rs

35 lines
1.3 KiB
Rust
Raw Normal View History

2021-02-05 22:38:44 -05:00
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
2019-01-22 17:01:33 -05:00
2021-02-05 22:38:44 -05:00
fn bench_dict_load(c: &mut Criterion) {
let mut group = c.benchmark_group("load");
group.bench_function(BenchmarkId::new("load", "builtin"), |b| {
b.iter(|| typos_cli::dict::BuiltIn::new(Default::default()));
});
group.finish();
2019-01-22 17:01:33 -05:00
}
2021-02-05 22:38:44 -05:00
fn bench_dict_lookup(c: &mut Criterion) {
let mut group = c.benchmark_group("lookup");
group.bench_function(BenchmarkId::new("lookup", "hit"), |b| {
let corrections = typos_cli::dict::BuiltIn::new(Default::default());
let input = typos::tokens::Word::new("successs", 0).unwrap();
assert_eq!(
corrections.correct_word(input),
Some(typos::Status::Corrections(vec![
std::borrow::Cow::Borrowed("successes")
]))
);
b.iter(|| corrections.correct_word(input));
});
group.bench_function(BenchmarkId::new("lookup", "miss"), |b| {
let corrections = typos_cli::dict::BuiltIn::new(Default::default());
let input = typos::tokens::Word::new("success", 0).unwrap();
assert!(corrections.correct_word(input).is_none());
b.iter(|| corrections.correct_word(input));
});
group.finish();
2019-01-22 17:01:33 -05:00
}
2021-02-05 22:38:44 -05:00
criterion_group!(benches, bench_dict_load, bench_dict_lookup);
criterion_main!(benches);