Add basic benchmark to Sobol sampler.

This commit is contained in:
Nathan Vegdahl 2021-01-10 00:20:22 +09:00
parent 285f714d02
commit 105d6e52b5
3 changed files with 46 additions and 0 deletions

4
Cargo.lock generated
View File

@ -608,6 +608,10 @@ checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8"
[[package]]
name = "sobol"
version = "0.1.0"
dependencies = [
"bencher",
"rand 0.6.5",
]
[[package]]
name = "spectral_upsampling"

View File

@ -9,3 +9,11 @@ build = "build.rs"
[lib]
name = "sobol"
path = "src/lib.rs"
[dev-dependencies]
rand = "0.6"
bencher = "0.1.5"
[[bench]]
name = "bench"
harness = false

View File

@ -0,0 +1,34 @@
use bencher::{benchmark_group, benchmark_main, black_box, Bencher};
use rand::{rngs::SmallRng, FromEntropy, Rng};
use sobol::sample_4d;
//----
fn gen_1000_samples(bench: &mut Bencher) {
bench.iter(|| {
for i in 0..1000u32 {
black_box(sample_4d(i, 0, 1234567890));
}
});
}
fn gen_1000_samples_incoherent(bench: &mut Bencher) {
let mut rng = SmallRng::from_entropy();
bench.iter(|| {
let s = rng.gen::<u32>();
let d = rng.gen::<u32>();
let seed = rng.gen::<u32>();
for i in 0..1000u32 {
black_box(sample_4d(
s.wrapping_add(i).wrapping_mul(512),
d.wrapping_add(i).wrapping_mul(97) % 32,
seed,
));
}
});
}
//----
benchmark_group!(benches, gen_1000_samples, gen_1000_samples_incoherent,);
benchmark_main!(benches);