mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-22 00:51:11 -05:00
perf(cli): Expand dict benchmark
This commit is contained in:
parent
592b36d23c
commit
5a05a06a70
1 changed files with 65 additions and 20 deletions
|
@ -8,27 +8,72 @@ fn bench_dict_load(c: &mut Criterion) {
|
|||
group.finish();
|
||||
}
|
||||
|
||||
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));
|
||||
});
|
||||
fn bench_dict_correct_word(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("correct_word");
|
||||
|
||||
{
|
||||
let case = "dict_fine";
|
||||
let input = "finalizes";
|
||||
group.bench_function(BenchmarkId::new("en", case), |b| {
|
||||
let corrections = typos_cli::dict::BuiltIn::new(typos_cli::config::Locale::En);
|
||||
let input = typos::tokens::Word::new(input, 0).unwrap();
|
||||
#[cfg(feature = "vars")]
|
||||
assert!(corrections.correct_word(input).is_none());
|
||||
b.iter(|| corrections.correct_word(input));
|
||||
});
|
||||
}
|
||||
{
|
||||
let case = "dict_correct";
|
||||
let input = "finallizes";
|
||||
let output = "finalizes";
|
||||
group.bench_function(BenchmarkId::new("en", case), |b| {
|
||||
let corrections = typos_cli::dict::BuiltIn::new(typos_cli::config::Locale::En);
|
||||
let input = typos::tokens::Word::new(input, 0).unwrap();
|
||||
assert_eq!(
|
||||
corrections.correct_word(input),
|
||||
Some(typos::Status::Corrections(vec![
|
||||
std::borrow::Cow::Borrowed(output)
|
||||
]))
|
||||
);
|
||||
b.iter(|| corrections.correct_word(input));
|
||||
});
|
||||
}
|
||||
{
|
||||
let case = "dict_correct_case";
|
||||
let input = "FINALLIZES";
|
||||
let output = "FINALIZES";
|
||||
group.bench_function(BenchmarkId::new("en", case), |b| {
|
||||
let corrections = typos_cli::dict::BuiltIn::new(typos_cli::config::Locale::En);
|
||||
let input = typos::tokens::Word::new(input, 0).unwrap();
|
||||
assert_eq!(
|
||||
corrections.correct_word(input),
|
||||
Some(typos::Status::Corrections(vec![
|
||||
std::borrow::Cow::Borrowed(output)
|
||||
]))
|
||||
);
|
||||
b.iter(|| corrections.correct_word(input));
|
||||
});
|
||||
}
|
||||
#[cfg(feature = "vars")]
|
||||
{
|
||||
let case = "dict_to_varcon";
|
||||
let input = "finalizes";
|
||||
let output = "finalises";
|
||||
group.bench_function(BenchmarkId::new("en-gb", case), |b| {
|
||||
let corrections = typos_cli::dict::BuiltIn::new(typos_cli::config::Locale::EnGb);
|
||||
let input = typos::tokens::Word::new(input, 0).unwrap();
|
||||
assert_eq!(
|
||||
corrections.correct_word(input),
|
||||
Some(typos::Status::Corrections(vec![
|
||||
std::borrow::Cow::Borrowed(output)
|
||||
]))
|
||||
);
|
||||
b.iter(|| corrections.correct_word(input));
|
||||
});
|
||||
}
|
||||
|
||||
group.finish();
|
||||
}
|
||||
|
||||
criterion_group!(benches, bench_dict_load, bench_dict_lookup);
|
||||
criterion_group!(benches, bench_dict_load, bench_dict_correct_word);
|
||||
criterion_main!(benches);
|
||||
|
|
Loading…
Reference in a new issue