Created
March 9, 2017 06:08
-
-
Save philippkeller/b378d98e9faa7e94dd4702bc8508d93c to your computer and use it in GitHub Desktop.
Benchmarking libc::random vs. XorShiftRng
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #![feature(test)] | |
| #![feature(rand)] | |
| extern crate test; | |
| extern crate rand; | |
| use rand::Rng; | |
| extern "C" { | |
| pub fn random() -> i64; | |
| pub fn srandom(arg1: u32); | |
| } | |
| #[cfg(test)] | |
| mod tests { | |
| use super::*; | |
| use test::Bencher; | |
| #[bench] | |
| fn libc_random(b: &mut Bencher) { | |
| b.iter(|| unsafe{random()}); | |
| } | |
| #[bench] | |
| fn xorshift_random(b: &mut Bencher) { | |
| let mut rng = rand::XorShiftRng::new_unseeded(); | |
| b.iter(|| rng.next_u64()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment