use criterion::*;

use renderer::{
    hitable::Hit, material::Lambertian, ray::Ray, sphere::Sphere, texture::ConstantTexture,
    vec3::Vec3,
};

fn criterion_benchmark(c: &mut Criterion) {
    let sphere = Sphere::new(
        Vec3::new(0., 0., 0.),
        1.,
        Lambertian::new(ConstantTexture::new([1., 0., 0.])),
    );
    let rays = vec![
        // Hit
        Ray::new([0., 0., -2.], [0., 0., 1.], 0.),
        // Miss
        Ray::new([0., 0., -2.], [0., 0., -1.], 0.),
    ];
    let mut group = c.benchmark_group("sphere");
    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()
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
