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
ThreadRng performance bug #43120
Comments
Since However, the question you should really be asking, is what kind of random numbers are you getting? Running your benchmark as written is 21ns/iter for me. Modifying your benchmark to cache the result of #[bench]
fn bench_rnd(b: &mut Bencher) {
let mut rng = rand::thread_rng();
b.iter(|| rng.gen_range::<f64>(2.0, 100.0));
} If I use #[bench]
fn bench_rnd(b: &mut Bencher) {
let mut rng = rand::weak_rng();
b.iter(|| rng.gen_range::<f64>(2.0, 100.0));
} |
Also note that Java's |
Thank you a lot for the explanation. |
ThreadRng works 5 times slower than ThreadLocalRandom in Java.
I run this benchmark in Rust:
On my laptop the result is:
test tests::bench_rnd ... bench: 49 ns/iter (+/- 1)
But if I run the same benchmark on JHM:
On my laptop the result is:
Benchmark Mode Cnt Score Error Units
Main.testRnd avgt 20 9,018 ± 0,094 ns/op
So the difference is 5.44 times looks like performance bug.
Meta
Rust:
rbose
rustc 1.20.0-nightly (c9bb935 2017-06-24)
binary: rustc
commit-hash: c9bb935
commit-date: 2017-06-24
host: x86_64-unknown-linux-gnu
release: 1.20.0-nightly
LLVM version: 4.0
Java:
OpenJDK 1.8.131
The text was updated successfully, but these errors were encountered: