test(dict): Bench more varcon cases

This commit is contained in:
Ed Page 2021-06-30 19:38:50 -05:00
parent 0144f4521f
commit 0e6d683ebe

View file

@ -12,18 +12,26 @@ fn bench_dict_correct_word(c: &mut Criterion) {
let mut group = c.benchmark_group("correct_word"); let mut group = c.benchmark_group("correct_word");
{ {
let case = "dict_fine"; let case = "ok";
let input = "finalizes"; let input = "finalizes";
group.bench_function(BenchmarkId::new("en", case), |b| { group.bench_function(BenchmarkId::new("en", case), |b| {
let corrections = typos_cli::dict::BuiltIn::new(typos_cli::config::Locale::En); let corrections = typos_cli::dict::BuiltIn::new(typos_cli::config::Locale::En);
let input = typos::tokens::Word::new(input, 0).unwrap(); let input = typos::tokens::Word::new(input, 0).unwrap();
#[cfg(feature = "vars")] #[cfg(feature = "vars")]
assert!(corrections.correct_word(input).is_none()); 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));
b.iter(|| corrections.correct_word(input)); b.iter(|| corrections.correct_word(input));
}); });
} }
{ {
let case = "dict_correct"; let case = "misspell";
let input = "finallizes"; let input = "finallizes";
let output = "finalizes"; let output = "finalizes";
group.bench_function(BenchmarkId::new("en", case), |b| { group.bench_function(BenchmarkId::new("en", case), |b| {
@ -37,9 +45,21 @@ fn bench_dict_correct_word(c: &mut Criterion) {
); );
b.iter(|| corrections.correct_word(input)); 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();
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 case = "misspell_case";
let input = "FINALLIZES"; let input = "FINALLIZES";
let output = "FINALIZES"; let output = "FINALIZES";
group.bench_function(BenchmarkId::new("en", case), |b| { group.bench_function(BenchmarkId::new("en", case), |b| {
@ -56,7 +76,7 @@ fn bench_dict_correct_word(c: &mut Criterion) {
} }
#[cfg(feature = "vars")] #[cfg(feature = "vars")]
{ {
let case = "dict_to_varcon"; let case = "varcon";
let input = "finalizes"; let input = "finalizes";
let output = "finalises"; let output = "finalises";
group.bench_function(BenchmarkId::new("en-gb", case), |b| { group.bench_function(BenchmarkId::new("en-gb", case), |b| {
@ -71,6 +91,23 @@ fn bench_dict_correct_word(c: &mut Criterion) {
b.iter(|| corrections.correct_word(input)); b.iter(|| corrections.correct_word(input));
}); });
} }
#[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));
});
}
group.finish(); group.finish();
} }