Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raw_detect perf tweaks #137

Merged
merged 2 commits into from Mar 16, 2024

Conversation

jqnatividad
Copy link
Contributor

Before:

running 4 tests
test bench_alphabet_cyrillic_calculate_scores ... bench:       1,923 ns/iter (+/- 60)
test bench_alphabet_latin_calculate_scores    ... bench:       2,706 ns/iter (+/- 151)
test bench_detect                             ... bench:   4,219,612 ns/iter (+/- 129,220)
test bench_detect_script                      ... bench:      73,365 ns/iter (+/- 3,556)

After tweaks:

running 4 tests
test bench_alphabet_cyrillic_calculate_scores ... bench:       1,917 ns/iter (+/- 68)
test bench_alphabet_latin_calculate_scores    ... bench:       2,748 ns/iter (+/- 98)
test bench_detect                             ... bench:   4,188,685 ns/iter (+/- 157,631)
test bench_detect_script                      ... bench:      69,409 ns/iter (+/- 4,946)

- applied clippy::needless_for_each lint (see https://rust-lang.github.io/rust-clippy/master/index.html#needless_for_each)
- declare scores vec with_capacity to minimize allocs
- explicitly declared vars (benchmarks show it helped)
Copy link
Contributor

@Ap3lsin4k Ap3lsin4k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirm that setting capacity is more performant.

src/combined/mod.rs Outdated Show resolved Hide resolved
Co-authored-by: Ænжej Theodorko <andy.theodorko@gmail.com>
@greyblake
Copy link
Owner

Thank you! Sorry for the delay.

@greyblake greyblake merged commit ce16b11 into greyblake:master Mar 16, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants