extern crate dsfmt;
extern crate test;

use test::Bencher;

use std::rand::{Rng, SeedableRng, Isaac64Rng, XorShiftRng};
use dsfmt::DSFMTRng;

#[bench]
fn bench_mt19937_1_000_000_rands(b: &mut Bencher){
    let mut rng: DSFMTRng = SeedableRng::from_seed(1);

    b.iter(||{
        for _ in range(1u, 1_000_000){
            rng.next_f64();
        }
    });
}

#[bench]
fn bench_isaac64_1_000_000_rands(b: &mut Bencher){
    let mut rng: Isaac64Rng = SeedableRng::from_seed([1u64].as_slice());

    b.iter(||{
        for _ in range(1u, 1_000_000){
            rng.next_f64();
        }
    });
}

#[bench]
fn bench_xor_1_000_000_rands(b: &mut Bencher){
    let mut rng: XorShiftRng = SeedableRng::from_seed([1u32, 1u32, 1u32, 1u32]);

    b.iter(||{
        for _ in range(1u, 1_000_000){
            rng.next_f64();
        }
    });
}

extern crate dsfmt;
extern crate test;

use test::Bencher;

use std::rand::{Rng, SeedableRng, Isaac64Rng, XorShiftRng};
use dsfmt::DSFMTRng;

#[bench]
fn bench_mt19937_1_000_000_rands(b: &mut Bencher){
    let mut rng: DSFMTRng = SeedableRng::from_seed(1);

    b.iter(||{
        for _ in range(1u, 1_000_000){
            test::black_box(rng.next_f64());
        }
    });
}

#[bench]
fn bench_isaac64_1_000_000_rands(b: &mut Bencher){
    let mut rng: Isaac64Rng = SeedableRng::from_seed([1u64].as_slice());

    b.iter(||{
        for _ in range(1u, 1_000_000){
            test::black_box(rng.next_f64());
        }
    });
}

#[bench]
fn bench_xor_1_000_000_rands(b: &mut Bencher){
    let mut rng: XorShiftRng = SeedableRng::from_seed([1u32, 1u32, 1u32, 1u32]);

    b.iter(||{
        for _ in range(1u, 1_000_000){
            test::black_box(rng.next_f64());
        }
    });
}

Add `black_box` calls to avoid f64 generation disappearing.
Add `black_box` calls to avoid f64 generation disappearing.

The final steps of generating an `f64` are fairly pure, and LLVM can see
this, so it just removes it, since the result is unused. The `black_box`
function is designed to manually overcome this, making the benchmarks
more representative.

Before:

    test bench_isaac64_1_000_000_rands ... bench:   6028930 ns/iter (+/- 133191)
    test bench_mt19937_1_000_000_rands ... bench:   1538384 ns/iter (+/- 43405)
    test bench_xor_1_000_000_rands     ... bench:   2368067 ns/iter (+/- 68618)

After:

    test bench_isaac64_1_000_000_rands ... bench:   6580334 ns/iter (+/- 199685)
    test bench_mt19937_1_000_000_rands ... bench:   3216404 ns/iter (+/- 84669)
    test bench_xor_1_000_000_rands     ... bench:   4135769 ns/iter (+/- 175282)
