Skip to content

Commit

Permalink
Benchmark alphabet_cyrillic_calculate_scores and alphabet_latin_calcu…
Browse files Browse the repository at this point in the history
…late_scores
  • Loading branch information
greyblake committed Apr 24, 2022
1 parent 879b654 commit 5f1ebeb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -96,7 +96,7 @@ For more details, please check a blog article [Introduction to Rust Whatlang Lib
This is mostly useful to test performance optimizations.

```
cargo bench
cargo bench --all-features
```

## Comparison with alternatives
Expand Down
33 changes: 30 additions & 3 deletions benches/example.rs
@@ -1,10 +1,11 @@
#[macro_use]
extern crate bencher;
extern crate serde_json;
extern crate whatlang;

use bencher::Bencher;
use std::collections::HashMap;
use whatlang::dev::{
alphabet_cyrillic_calculate_scores, alphabet_latin_calculate_scores, FilterList, LowercaseText,
};
use whatlang::{detect, detect_script};

fn bench_detect(bench: &mut Bencher) {
Expand All @@ -29,5 +30,31 @@ fn bench_detect_script(bench: &mut Bencher) {
})
}

benchmark_group!(benches, bench_detect, bench_detect_script);
fn bench_alphabet_latin_calculate_scores(bench: &mut Bencher) {
let text = "Ich sehe auf die Uhr. Es ist kurz vor Mittag, und da heute Sonnabend ist, mache ich Schluß. Por ke lingvo internacia povu bone kaj regule progresadi kaj por ke ĝi havu plenan certecon, ke ĝi neniam disfalos kaj ia facilanima paŝo de ĝiaj amikoj estontaj ne detruos la laborojn de ĝiaj amikoj estintaj, - estas plej necesa antaŭ ĉio unu kondiĉo: la ezistado de klare difinita, neniam tuŝebla kaj neniam ŝangebla Fundamento de la lingvo.";
let lowercase_text = LowercaseText::new(text);
let filter = FilterList::All;

bench.iter(|| {
alphabet_latin_calculate_scores(&lowercase_text, &filter);
})
}

fn bench_alphabet_cyrillic_calculate_scores(bench: &mut Bencher) {
let text = "Творець есперанто Людвік Заменгоф назвав свою мову просто Lingvo internacia «міжнародна мова». Оскільки на той час у Європі популярною була інша штучна мова — волапюк, прихильники есперанто часто казали «мова доктора Есперанто». Згодом це формулювання скоротилося до «мова Есперанто», а врешті-решт залишилося одне лише слово «Esperanto», яке есперантською пишуть з великої літери, аби його можна було відрізнити від слова «людина, яка сподівається»";
let lowercase_text = LowercaseText::new(text);
let filter = FilterList::All;

bench.iter(|| {
alphabet_cyrillic_calculate_scores(&lowercase_text, &filter);
})
}

benchmark_group!(
benches,
bench_detect,
bench_detect_script,
bench_alphabet_latin_calculate_scores,
bench_alphabet_cyrillic_calculate_scores,
);
benchmark_main!(benches);
4 changes: 2 additions & 2 deletions src/alphabets/mod.rs
@@ -1,6 +1,6 @@
mod cyrillic;
pub(crate) mod cyrillic;
pub(crate) mod detection;
mod latin;
pub(crate) mod latin;

pub use detection::{detect, raw_detect};

Expand Down
6 changes: 5 additions & 1 deletion src/dev.rs
Expand Up @@ -9,9 +9,13 @@ pub use crate::lang::Lang;
pub use crate::scripts::{detect_script, raw_detect_script, RawScriptInfo, Script};
pub use crate::trigrams::{raw_detect as trigrams_raw_detect, RawOutcome as RawTrigramsInfo};

pub use crate::alphabets::cyrillic::alphabet_calculate_scores as alphabet_cyrillic_calculate_scores;
pub use crate::alphabets::latin::alphabet_calculate_scores as alphabet_latin_calculate_scores;
pub use crate::core::{FilterList, LowercaseText};

// private imports
use crate::core::detect::detect_lang_base_on_mandarin_script;
use crate::core::{FilterList, Query};
use crate::core::Query;
use crate::scripts::grouping::ScriptLangGroup;

#[derive(Debug)]
Expand Down

0 comments on commit 5f1ebeb

Please sign in to comment.