#![feature(test)]
extern crate test;
use test::Bencher;
use randomize::*;
use std::time::{SystemTime, UNIX_EPOCH};
pub fn u64_from_time() -> u64 {
let unix_delta = match SystemTime::now().duration_since(UNIX_EPOCH) {
Ok(duration) => duration,
Err(system_time_error) => system_time_error.duration(),
};
if unix_delta.subsec_nanos() != 0 {
unix_delta.as_secs().wrapping_mul(unix_delta.subsec_nanos() as u64)
} else {
unix_delta.as_secs()
}
}
#[bench]
fn bench_xsh_rr_16_8(b: &mut Bencher) {
let mut state = u64_from_time() as u16;
b.iter(|| state = xsh_rr_16_8(state) as u16);
}
#[bench]
fn bench_xsh_rr_32_16(b: &mut Bencher) {
let mut state = u64_from_time() as u32;
b.iter(|| state = xsh_rr_32_16(state) as u32);
}
#[bench]
fn bench_xsh_rr_64_32(b: &mut Bencher) {
let mut state = u64_from_time();
b.iter(|| state = xsh_rr_64_32(state) as u64);
}
#[bench]
fn bench_xsh_rr_128_64(b: &mut Bencher) {
let mut state = ((u64_from_time() as u128) << 64) | (u64_from_time() as u128);
b.iter(|| state = xsh_rr_128_64(state) as u128);
}