48 lines
1.9 KiB
Rust
48 lines
1.9 KiB
Rust
use criterion::*;
|
|
use renderer::{aabb::AABB, ray::Ray};
|
|
|
|
fn bench(c: &mut Criterion) {
|
|
let bb = AABB::new([1., -1., -1.], [3., 1., 1.]);
|
|
let r_hit = Ray::new([0., 0., 0.], [1., 0., 0.], 0.);
|
|
let r_miss = Ray::new([0., 0., 0.], [-1., 0., 0.], 0.);
|
|
let t_min = 0.001;
|
|
let t_max = f32::MAX;
|
|
|
|
let mut group = c.benchmark_group("aabb");
|
|
group.throughput(Throughput::Elements(1));
|
|
group.bench_with_input(BenchmarkId::new("hit_naive", "r_hit"), &r_hit, |b, r| {
|
|
b.iter(|| bb.hit_naive(*r, t_min, t_max))
|
|
});
|
|
group.bench_with_input(BenchmarkId::new("hit2", "r_hit"), &r_hit, |b, r| {
|
|
b.iter(|| bb.hit2(*r, t_min, t_max))
|
|
});
|
|
//group.bench_with_input(BenchmarkId::new("hit_precompute", "r_hit"), &r_hit, |b, r| { b.iter(|| bb.hit_precompute(*r, t_min, t_max)) });
|
|
group.bench_with_input(BenchmarkId::new("hit_fast", "r_hit"), &r_hit, |b, r| {
|
|
b.iter(|| bb.hit_fast(*r, t_min, t_max))
|
|
});
|
|
#[cfg(target_arch = "x86_64")]
|
|
group.bench_with_input(BenchmarkId::new("hit_simd", "r_hit"), &r_hit, |b, r| {
|
|
b.iter(|| bb.hit_simd(*r, t_min, t_max))
|
|
});
|
|
|
|
group.bench_with_input(BenchmarkId::new("hit_naive", "r_miss"), &r_miss, |b, r| {
|
|
b.iter(|| bb.hit_naive(*r, t_min, t_max))
|
|
});
|
|
group.bench_with_input(BenchmarkId::new("hit2", "r_miss"), &r_miss, |b, r| {
|
|
b.iter(|| bb.hit2(*r, t_min, t_max))
|
|
});
|
|
//group.bench_with_input(BenchmarkId::new("hit_precompute", "r_miss"), &r_miss, |b, r| { b.iter(|| bb.hit_precompute(*r, t_min, t_max)) });
|
|
group.bench_with_input(BenchmarkId::new("hit_fast", "r_miss"), &r_miss, |b, r| {
|
|
b.iter(|| bb.hit_fast(*r, t_min, t_max))
|
|
});
|
|
#[cfg(target_arch = "x86_64")]
|
|
group.bench_with_input(BenchmarkId::new("hit_simd", "r_miss"), &r_miss, |b, r| {
|
|
b.iter(|| bb.hit_simd(*r, t_min, t_max))
|
|
});
|
|
|
|
group.finish();
|
|
}
|
|
|
|
criterion_group!(benches, bench);
|
|
criterion_main!(benches);
|