greyblake / whatlang-rs

Natural language detection library for Rust. Try demo online: https://whatlang.org/
https://whatlang.org/
MIT License
969 stars 109 forks source link

Replace hashbrown::HashMap with std::collections::HashMap #119

Closed greyblake closed 2 years ago

greyblake commented 2 years ago

This a code changes for https://github.com/greyblake/whatlang-rs/issues/98

Benchmarks

hashbrown::HashMap

running 4 tests
test bench_alphabet_cyrillic_calculate_scores ... bench:       2,157 ns/iter (+/- 23)
test bench_alphabet_latin_calculate_scores    ... bench:       2,431 ns/iter (+/- 80)
test bench_detect                             ... bench:   4,254,212 ns/iter (+/- 108,815)
test bench_detect_script                      ... bench:     107,647 ns/iter (+/- 2,975)

std::collections::HashMap

test bench_alphabet_cyrillic_calculate_scores ... bench:       1,937 ns/iter (+/- 372)
test bench_alphabet_latin_calculate_scores    ... bench:       2,206 ns/iter (+/- 81)
test bench_detect                             ... bench:   9,446,431 ns/iter (+/- 147,967)
test bench_detect_script                      ... bench:     111,002 ns/iter (+/- 4,825)

detect() becomes 2x slower when with std::collections::HashMap.