rust-random / book

The Rust Rand Book
Other
49 stars 19 forks source link

Mention ChaCha8 generator #8

Closed vks closed 5 years ago

vks commented 5 years ago

This is an interesting alternative to the non-CSPRNGs, since it is about as fast/faster than many of them.

vks commented 5 years ago

Benchmarks:

test gen_bytes_chacha12             ... bench:     335,135 ns/iter (+/- 5,118) = 3055 MB/s
test gen_bytes_chacha20             ... bench:     504,586 ns/iter (+/- 16,726) = 2029 MB/s
test gen_bytes_chacha8              ... bench:     251,957 ns/iter (+/- 3,463) = 4064 MB/s
test gen_bytes_hc128                ... bench:     462,396 ns/iter (+/- 4,081) = 2214 MB/s
test gen_bytes_isaac                ... bench:     718,384 ns/iter (+/- 62,118) = 1425 MB/s
test gen_bytes_isaac64              ... bench:     385,250 ns/iter (+/- 8,200) = 2658 MB/s
test gen_bytes_lcg64_xsh32          ... bench:     617,052 ns/iter (+/- 33,270) = 1659 MB/s
test gen_bytes_mcg128_xsh64         ... bench:     323,854 ns/iter (+/- 7,361) = 3161 MB/s
test gen_bytes_os                   ... bench:  61,325,527 ns/iter (+/- 1,325,821) = 16 MB/s
test gen_bytes_small                ... bench:     325,099 ns/iter (+/- 32,972) = 3149 MB/s
test gen_bytes_splitmix64           ... bench:     233,722 ns/iter (+/- 14,390) = 4381 MB/s
test gen_bytes_std                  ... bench:     464,099 ns/iter (+/- 6,304) = 2206 MB/s
test gen_bytes_xoroshiro128plus     ... bench:     329,572 ns/iter (+/- 15,344) = 3107 MB/s
test gen_bytes_xoroshiro128starstar ... bench:     330,224 ns/iter (+/- 4,924) = 3100 MB/s
test gen_bytes_xoroshiro64star      ... bench:     508,351 ns/iter (+/- 11,159) = 2014 MB/s
test gen_bytes_xoroshiro64starstar  ... bench:     522,536 ns/iter (+/- 9,524) = 1959 MB/s
test gen_bytes_xorshift             ... bench:     368,437 ns/iter (+/- 4,574) = 2779 MB/s
test gen_bytes_xoshiro128plus       ... bench:     463,197 ns/iter (+/- 29,034) = 2210 MB/s
test gen_bytes_xoshiro128starstar   ... bench:     462,240 ns/iter (+/- 6,285) = 2215 MB/s
test gen_bytes_xoshiro256plus       ... bench:     357,846 ns/iter (+/- 11,615) = 2861 MB/s
test gen_bytes_xoshiro256starstar   ... bench:     346,764 ns/iter (+/- 6,309) = 2953 MB/s

test gen_u64_chacha12               ... bench:       4,414 ns/iter (+/- 447) = 1812 MB/s
test gen_u64_chacha20               ... bench:       5,602 ns/iter (+/- 410) = 1428 MB/s
test gen_u64_chacha8                ... bench:       3,505 ns/iter (+/- 174) = 2282 MB/s
test gen_u64_hc128                  ... bench:       3,693 ns/iter (+/- 247) = 2166 MB/s
test gen_u64_isaac                  ... bench:       6,967 ns/iter (+/- 376) = 1148 MB/s
test gen_u64_isaac64                ... bench:       3,583 ns/iter (+/- 150) = 2232 MB/s
test gen_u64_lcg64_xsh32            ... bench:       2,445 ns/iter (+/- 146) = 3271 MB/s
test gen_u64_mcg128_xsh64           ... bench:       1,573 ns/iter (+/- 107) = 5085 MB/s
test gen_u64_os                     ... bench:     874,107 ns/iter (+/- 127,534) = 9 MB/s
test gen_u64_small                  ... bench:       1,552 ns/iter (+/- 47) = 5154 MB/s
test gen_u64_splitmix64             ... bench:         982 ns/iter (+/- 27) = 8146 MB/s
test gen_u64_std                    ... bench:       3,684 ns/iter (+/- 63) = 2171 MB/s
test gen_u64_xoroshiro128plus       ... bench:       1,104 ns/iter (+/- 25) = 7246 MB/s
test gen_u64_xoroshiro128starstar   ... bench:       1,243 ns/iter (+/- 33) = 6436 MB/s
test gen_u64_xoroshiro64star        ... bench:       2,902 ns/iter (+/- 52) = 2756 MB/s
test gen_u64_xoroshiro64starstar    ... bench:       3,109 ns/iter (+/- 74) = 2573 MB/s
test gen_u64_xorshift               ... bench:       1,558 ns/iter (+/- 24) = 5134 MB/s
test gen_u64_xoshiro128plus         ... bench:       1,607 ns/iter (+/- 69) = 4978 MB/s
test gen_u64_xoshiro128starstar     ... bench:       1,910 ns/iter (+/- 58) = 4188 MB/s
test gen_u64_xoshiro256plus         ... bench:         839 ns/iter (+/- 43) = 9535 MB/s
test gen_u64_xoshiro256starstar     ... bench:         934 ns/iter (+/- 30) = 8565 MB/s

(It's a bit fishy that for some generators the MB/s for gen_u64 is higher than for gen_bytes.)