rtiow: add aabb tests and benchmark along with terrible SIMD impl.

This commit is contained in:
2023-01-22 12:03:17 -08:00
parent 27d6c1280b
commit 2d696932e3
5 changed files with 145 additions and 38 deletions

View File

@@ -1,16 +1,45 @@
use criterion::*;
fn decode(bytes: &[u8]) {
// Decode the bytes
//...
}
use renderer::{aabb::AABB, ray::Ray};
fn bench(c: &mut Criterion) {
let bytes: &[u8] = b"some bytes";
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))
});
let mut group = c.benchmark_group("throughput-example");
group.throughput(Throughput::Bytes(bytes.len() as u64));
group.bench_function("decode", |b| b.iter(|| decode(bytes)));
group.finish();
}

View File

@@ -1,6 +1,3 @@
#[macro_use]
extern crate criterion;
use criterion::*;
use renderer::{
@@ -21,13 +18,13 @@ fn criterion_benchmark(c: &mut Criterion) {
Ray::new([0., 0., -2.], [0., 0., -1.], 0.),
];
let mut group = c.benchmark_group("sphere");
for r in rays {
group.bench_with_input(
BenchmarkId::new("Sphere", format!("{:?}", r)),
&r,
|b, r| b.iter(|| sphere.hit(*r, 0., 1.)),
);
}
group.throughput(Throughput::Elements(1));
group.bench_with_input(BenchmarkId::new("Sphere", "hit"), &rays[0], |b, r| {
b.iter(|| sphere.hit(*r, 0., 1.))
});
group.bench_with_input(BenchmarkId::new("Sphere", "miss"), &rays[1], |b, r| {
b.iter(|| sphere.hit(*r, 0., 1.))
});
group.finish()
}