typos/benches/corrections.rs

117 lines
4.5 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-06-03 22:38:02 -04:00
fn bench_dict_correct_word(c: &mut Criterion) {
let mut group = c.benchmark_group("correct_word");
{
2021-06-30 20:38:50 -04:00
let case = "ok";
2021-06-03 22:38:02 -04:00
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")]
2021-06-30 20:38:50 -04:00
assert_eq!(corrections.correct_word(input), None);
b.iter(|| corrections.correct_word(input));
});
#[cfg(feature = "vars")]
group.bench_function(BenchmarkId::new("en-us", case), |b| {
let corrections = typos_cli::dict::BuiltIn::new(typos_cli::config::Locale::EnUs);
let input = typos::tokens::Word::new(input, 0).unwrap();
#[cfg(feature = "vars")]
assert_eq!(corrections.correct_word(input), Some(typos::Status::Valid));
2021-06-03 22:38:02 -04:00
b.iter(|| corrections.correct_word(input));
});
}
{
2021-06-30 20:38:50 -04:00
let case = "misspell";
2021-06-03 22:38:02 -04:00
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));
});
2021-06-30 20:38:50 -04:00
#[cfg(feature = "vars")]
group.bench_function(BenchmarkId::new("en-us", case), |b| {
let corrections = typos_cli::dict::BuiltIn::new(typos_cli::config::Locale::EnUs);
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));
});
2021-06-03 22:38:02 -04:00
}
{
2021-06-30 20:38:50 -04:00
let case = "misspell_case";
2021-06-03 22:38:02 -04:00
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")]
{
2021-06-30 20:38:50 -04:00
let case = "varcon";
2021-06-03 22:38:02 -04:00
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));
});
}
2021-06-30 20:38:50 -04:00
#[cfg(feature = "vars")]
{
let case = "misspell_varcon";
let input = "finallizes";
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));
});
}
2021-06-03 22:38:02 -04:00
2021-02-05 22:38:44 -05:00
group.finish();
2019-01-22 17:01:33 -05:00
}
2021-06-03 22:38:02 -04:00
criterion_group!(benches, bench_dict_load, bench_dict_correct_word);
2021-02-05 22:38:44 -05:00
criterion_main!(benches);