use std::time::Instant;
use hunspell_rs::{CheckResult, Hunspell};
use spellbook::Dictionary;
fn test_hunspell() {
let fr_dict = Hunspell::new(
"/usr/share/hunspell/fr_FR.aff",
"/usr/share/hunspell/fr_FR.dic",
);
let en_dict = Hunspell::new(
"/usr/share/hunspell/en_US.aff",
"/usr/share/hunspell/en_US.dic",
);
let de_dict = Hunspell::new(
"/home/brie/Downloads/de_DE.aff",
"/home/brie/Downloads/de_DE.dic",
);
let dur = Instant::now();
assert!(en_dict.check("test") == CheckResult::FoundInDictionary);
println!("en_US correct word: {:?}", dur.elapsed());
let dur = Instant::now();
assert!(fr_dict.check("test") == CheckResult::FoundInDictionary);
println!("fr_FR correct word: {:?}", dur.elapsed());
let dur = Instant::now();
assert!(en_dict.check("foobarbaz") != CheckResult::FoundInDictionary);
println!("en_US incorrect word: {:?}", dur.elapsed());
let dur = Instant::now();
assert!(fr_dict.check("foobarbaz") != CheckResult::FoundInDictionary);
println!("fr_FR incorrect word: {:?}", dur.elapsed());
let dur = Instant::now();
let suggestions = en_dict.suggest("impécable");
println!("en_US impécable suggestions: {:?}", dur.elapsed());
println!("Suggestions: {suggestions:?}");
let dur = Instant::now();
let suggestions = fr_dict.suggest("impécable");
println!("fr_FR impécable suggestions: {:?}", dur.elapsed());
println!("Suggestions: {suggestions:?}");
let dur = Instant::now();
let suggestions = en_dict.suggest("réceptioniste");
println!("en_US réceptioniste suggestions: {:?}", dur.elapsed());
println!("Suggestions: {suggestions:?}");
let dur = Instant::now();
let suggestions = fr_dict.suggest("réceptioniste");
println!("fr_FR réceptioniste suggestions: {:?}", dur.elapsed());
println!("Suggestions: {suggestions:?}");
let dur = Instant::now();
let suggestions = de_dict.suggest("frühstrucken");
println!("de_DE frühstrucken suggestions: {:?}", dur.elapsed());
println!("Suggestions: {suggestions:?}");
}
fn test_spellbook() {
let fr_aff = std::fs::read_to_string("/usr/share/hunspell/fr_FR.aff").unwrap();
let fr_dic = std::fs::read_to_string("/usr/share/hunspell/fr_FR.dic").unwrap();
let fr_dict = Dictionary::new(&fr_aff, &fr_dic).unwrap();
let en_aff = std::fs::read_to_string("/usr/share/hunspell/en_US.aff").unwrap();
let en_dic = std::fs::read_to_string("/usr/share/hunspell/en_US.dic").unwrap();
let en_dict = Dictionary::new(&en_aff, &en_dic).unwrap();
let de_aff = std::fs::read_to_string("/home/brie/Downloads/de_DE.aff").unwrap();
let de_dic = std::fs::read_to_string("/home/brie/Downloads/de_DE.dic").unwrap();
let de_dict = Dictionary::new(&de_aff, &de_dic).unwrap();
let dur = Instant::now();
assert!(en_dict.check("test"));
println!("en_US correct word: {:?} ", dur.elapsed());
let dur = Instant::now();
assert!(fr_dict.check("test"));
println!("fr_FR correct word: {:?} ", dur.elapsed());
let dur = Instant::now();
assert!(!en_dict.check("foobarbaz"));
println!("en_US incorrect word: {:?}", dur.elapsed());
let dur = Instant::now();
assert!(!fr_dict.check("foobarbaz"));
println!("fr_FR incorrect word: {:?}", dur.elapsed());
let mut suggestions = Vec::new();
let dur = Instant::now();
en_dict.suggest("impécable", &mut suggestions);
println!("en_US impécable suggestions: {:?}", dur.elapsed());
println!("Suggestions: {suggestions:?}");
let dur = Instant::now();
fr_dict.suggest("impécable", &mut suggestions);
println!("fr_FR impécable suggestions: {:?}", dur.elapsed());
println!("Suggestions: {suggestions:?}");
let dur = Instant::now();
en_dict.suggest("réceptioniste", &mut suggestions);
println!("en_US réceptioniste suggestions: {:?}", dur.elapsed());
println!("Suggestions: {suggestions:?}");
let dur = Instant::now();
fr_dict.suggest("réceptioniste", &mut suggestions);
println!("fr_FR réceptioniste suggestions: {:?}", dur.elapsed());
println!("Suggestions: {suggestions:?}");
let dur = Instant::now();
de_dict.suggest("frühstrucken", &mut suggestions);
println!("de_DE frühstrucken suggestions: {:?}", dur.elapsed());
println!("Suggestions: {suggestions:?}");
}
fn main() {
println!("Hunspell:");
test_hunspell();
println!("----------");
println!("Spellbook:");
test_spellbook();
}
Spellchecking performance seems especially bad in French (compared to German or English), even after #14
This was also originally found by @new-years-eve, but I did a bit of testing around it.
Some testing data (formatted for clarity):
(before #14, impécable took ~30 seconds, I killed my test for réceptioniste after 15 minutes)
Click to expand (Hunspell results)
Click to expand (source code)
I can provide dictionary files to replicate if necessary, but I'm just using French and English from the standard fedora 43 packages (
hunspell-en,hunspell-fr). The German package is from Arch Linux, since the Fedora de_DE dictionary uses ISO-8859 instead of UTF-8 (and spellbook cannot handle non-UTF-8)I'm well aware that the README doesn't guarantee that this will work well:
It seemed like this was (potentially) bad enough to be worth an issue