18 Performance
John Zacarias Jekel edited this page 1 year ago

Summary

Anslatortray Version Time* in Regular mode (ns) Time* in Byte-String Mode (ns)
main branch 40.27 40.25
0.5.0 40.27 40.25
0.4.0 128.971 (old UTF-8 mode) 93.986 (old ASCII mode)
0.3.0 227.462 (old UTF-8 mode) N/A

* The time to translate the average word in the words_alpha.txt file from https://github.com/dwyl/english-words.

Test results for the current Anslatortray main branch

On my dated system with dual Intel(R) Xeon(R) E5-2670 v2 CPUs, the translate() function can process one word every 40.27 nanoseconds on average in regular mode, and one word every 40.25 nanoseconds on average in byte string mode. The words_alpha.txt file from https://github.com/dwyl/english-words was fed to the anslatortray --benchmark-file set to 1000 iterations, and then the averages produced were divided by 370105 (the number of words in the file).

> anslatortray --benchmark-file ./words_alpha.txt 1000
Anslatortray: frontend for the Anslatortray for Rust library

Sucessful: Regular translation took 14903753ns to translate on average over 1000 runs.
Sucessful: Byte-string translation with reused allocations took 14897940ns to translate on average over 1000 runs.

Test results for Anslatortray 0.5.0

From Anslatortray 0.4.0 to 0.5.0, the ASCII translation functions were removed, as were the UTF-8 translation functions. Instead, there are new "byte string" functions that operate on u8 slices and Vecs. In addition to being exposed to the user directly, they are also used to power the "regular" (originally called UTF-8) translation functions.

On my dated system with dual Intel(R) Xeon(R) E5-2670 v2 CPUs, the translate() function can process one word every 40.27 nanoseconds on average in regular mode, and one word every 40.25 nanoseconds on average in byte string mode. The words_alpha.txt file from https://github.com/dwyl/english-words was fed to the anslatortray --benchmark-file set to 1000 iterations, and then the averages produced were divided by 370105 (the number of words in the file).

> anslatortray --benchmark-file ./words_alpha.txt 1000
Anslatortray: frontend for the Anslatortray for Rust library

Sucessful: Regular translation took 14903753ns to translate on average over 1000 runs.
Sucessful: Byte-string translation with reused allocations took 14897940ns to translate on average over 1000 runs.

Test results for Anslatortray 0.4.0

From Anslatortray 0.3.0 to 0.4.0, the various included programs were consolidated into a single anslatortray binary. In addition, this binary recieved a new option --benchmark-file, which makes it much easier to evaluate the time it takes to translate a particular file.

On my dated system with dual Intel(R) Xeon(R) E5-2670 v2 CPUs, the translate() function can process one word every 128.971 nanoseconds on average in the default UTF-8 mode, and one word every 93.986 nanoseconds on average in the ASCII-only mode. The words_alpha.txt file from https://github.com/dwyl/english-words was fed to the anslatortray --benchmark-file set to 1000 iterations, and then the averages produced were divided by 370105 (the number of words in the file).

> anslatortray --benchmark-file ./words_alpha.txt 1000
Anslatortray: frontend for the Anslatortray for Rust library

Sucessful: UTF-8 translation took 47732914ns to translate on average over 1000 runs.
Sucessful: ASCII translation took 34784643ns to translate on average over 1000 runs

Although cargo bench --features nightly-features benchmarks are still supported, I am no longer including them on this page as what they actually compute changes frequently. They're mostly intended for quick regression testing during development.

Test results for Anslatortray 0.3.0

On my dated system with dual Intel(R) Xeon(R) E5-2670 v2 CPUs, the translate() function can process one word every 227.462 nanoseconds on average. I tested this by feeding the words_alpha.txt file from https://github.com/dwyl/english-words to anslatetray-file 10 times, calculating the average runtime, and dividing by 370105 (the number of words in the file). The times do not including loading from and writing to the disk.

Note that raw calls to translate_word() would be faster, but translate() has to be smart enough to preserve symbols and whitespace surrounding each word, while still accounting for contractions and other edge-cases.

> for run in {1..10}; do anslatetray-file words_alpha.txt words_alpha_pig_latin.txt; done
Sucessful: took 90144337ns to translate
Sucessful: took 82581222ns to translate
Sucessful: took 82803035ns to translate
Sucessful: took 80643452ns to translate
Sucessful: took 80542962ns to translate
Sucessful: took 81848295ns to translate
Sucessful: took 81600103ns to translate
Sucessful: took 86463460ns to translate
Sucessful: took 87399299ns to translate
Sucessful: took 87821022ns to translate

There are also some benchmarks built into the library that you can run to easily check the performance of it on your system:

> cargo bench --features nightly-features
[...]
test translate_strings::benches::translate_ferb_lorem_ipsum            ... bench:      11,284 ns/iter (+/- 331)
test translate_strings::benches::translate_ferb_project_description    ... bench:       1,852 ns/iter (+/- 28)
test translate_strings::benches::translate_lorem_ipsum                 ... bench:      11,033 ns/iter (+/- 284)
test translate_strings::benches::translate_project_description         ... bench:       1,848 ns/iter (+/- 61)
test translate_strings::benches::translate_yay_lorem_ipsum             ... bench:      10,968 ns/iter (+/- 263)
test translate_strings::benches::translate_yay_project_description     ... bench:       1,809 ns/iter (+/- 40)
test translate_words::benches::translate_word_ferb_the_word_translator ... bench:         120 ns/iter (+/- 3)
test translate_words::benches::translate_word_the_word_translator      ... bench:         126 ns/iter (+/- 7)
test translate_words::benches::translate_word_yay_the_word_translator  ... bench:         121 ns/iter (+/- 6)
[...]

Anslatortray is quite fast, but it could be faster :). Both the speed and the quality of translation are priorities for me, and I'm working to improve them both!