-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Description
ThreadRng works 5 times slower than ThreadLocalRandom in Java.
I run this benchmark in Rust:
#[bench]
fn bench_rnd(b: &mut Bencher) {
b.iter(|| rand::thread_rng().gen_range::<f64>(2.0, 100.0));
}
On my laptop the result is:
test tests::bench_rnd ... bench: 49 ns/iter (+/- 1)
But if I run the same benchmark on JHM:
@Benchmark
public double testRnd() {
return ThreadLocalRandom.current().nextDouble(2, 100);
}
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
Metadata
Metadata
Assignees
Labels
No labels