Update benchmark

This commit is contained in:
Matthew Gordon 2020-03-16 19:54:08 -04:00
parent b13cbe316d
commit 4042b266ae
2 changed files with 51 additions and 34 deletions

View File

@ -4,7 +4,8 @@ version = "0.1.0"
authors = ["Matthew Gordon <matthew.scott.gordon@gmail.com>"] authors = ["Matthew Gordon <matthew.scott.gordon@gmail.com>"]
edition = "2018" edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features]
slow_tests = []
[dependencies] [dependencies]
alga = "0.9" alga = "0.9"
@ -23,6 +24,11 @@ features = ["arbitrary"]
[profile.dev] [profile.dev]
opt-level = 3 opt-level = 3
[profile.bench]
opt-level = 3
lto = true
codegen-units = 1
[profile.release] [profile.release]
opt-level = 3 opt-level = 3
lto = true lto = true

View File

@ -1,3 +1,5 @@
#![feature(test)]
pub mod camera; pub mod camera;
pub mod colour; pub mod colour;
pub mod image; pub mod image;
@ -12,54 +14,42 @@ pub mod util;
use realtype::Real; use realtype::Real;
#[cfg(bench)] #[cfg(test)]
mod tests { mod tests {
extern crate test; extern crate test;
use test::Bencher; use test::Bencher;
use super::camera::render_scene; use crate::camera::partial_render_scene;
use super::colour::{ColourRgbF, NamedColour}; use crate::colour::{ColourRgbF, NamedColour};
use super::image::ImageRgbF; use crate::materials::{LambertianMaterial, PhongMaterial, ReflectiveMaterial};
use super::materials::{LambertianMaterial, PhongMaterial, ReflectiveMaterial}; use crate::mesh::load_obj;
use super::mesh::load_obj; use crate::raycasting::{BoundingVolumeHierarchy, Plane, Primitive, Sphere};
use super::raycasting::{Intersect, Plane, Sphere}; use crate::scene::Scene;
use super::scene::Scene; use crate::util::Tile;
use nalgebra::{Point3, Vector3}; use nalgebra::{Point3, Vector3};
use std::path::Path; use std::path::Path;
use std::sync::{Arc, Mutex}; use std::sync::Arc;
#[cfg(feature = "slow_tests")]
#[bench] #[bench]
fn simple_scene(b: &mut Bencher) { fn simple_scene(b: &mut Bencher) {
let image_width = 3; let image_width = 4;
let image_height = 3; let image_height = 4;
let output_image = Arc::new(Mutex::new(ImageRgbF::<f64>::new(image_width, image_height)));
let scene = Arc::new(Scene { let scene = Arc::new(Scene {
camera_location: Point3::new(-2.0, 1.0, -5.0), camera_location: Point3::new(-2.0, 1.0, -5.0),
objects: load_obj( objects: vec![
Path::new("/home/matthew/Downloads/bunny.obj"), Arc::new(Plane::new(
Arc::new(ReflectiveMaterial {
colour: ColourRgbF::from_named(NamedColour::Yellow),
diffuse_strength: 0.05,
reflection_strength: 0.9,
}),
)
.unwrap()
.into_iter()
.map(|triangle| Box::new(triangle) as Box<dyn Intersect<f64>>)
.chain(vec![
Box::new(Plane::new(
Vector3::new(0.0, 1.0, 0.0), Vector3::new(0.0, 1.0, 0.0),
-2.0, -2.0,
Arc::new(LambertianMaterial { Arc::new(LambertianMaterial {
colour: ColourRgbF::new(0.55, 0.27, 0.04), colour: ColourRgbF::new(0.55, 0.27, 0.04),
diffuse_strength: 0.1, diffuse_strength: 0.1,
}), }),
)) as Box<dyn Intersect<f64>>, )) as Arc<dyn Primitive<f64>>,
Box::new(Sphere::new( Arc::new(Sphere::new(
Point3::new(-6.25, -0.5, 1.0), Point3::new(-6.25, -0.5, 1.0),
1.0, 1.0,
Arc::new(LambertianMaterial { Arc::new(LambertianMaterial {
@ -67,7 +57,7 @@ mod tests {
diffuse_strength: 0.1, diffuse_strength: 0.1,
}), }),
)), )),
Box::new(Sphere::new( Arc::new(Sphere::new(
Point3::new(-4.25, -0.5, 2.0), Point3::new(-4.25, -0.5, 2.0),
1.0, 1.0,
Arc::new(ReflectiveMaterial { Arc::new(ReflectiveMaterial {
@ -76,7 +66,7 @@ mod tests {
reflection_strength: 0.99, reflection_strength: 0.99,
}), }),
)), )),
Box::new(Sphere::new( Arc::new(Sphere::new(
Point3::new(-5.0, 1.5, 1.0), Point3::new(-5.0, 1.5, 1.0),
1.0, 1.0,
Arc::new(PhongMaterial { Arc::new(PhongMaterial {
@ -86,9 +76,30 @@ mod tests {
specular_strength: 1.0, specular_strength: 1.0,
}), }),
)), )),
]) Arc::new(BoundingVolumeHierarchy::build(
.collect(), &load_obj(
Path::new("/home/matthew/Downloads/bunny.obj"),
Arc::new(PhongMaterial {
colour: ColourRgbF::from_named(NamedColour::Yellow),
diffuse_strength: 0.05,
smoothness: 100.0,
specular_strength: 1.0,
}),
)
.unwrap(),
)),
],
});
b.iter(move || {
let scene_ptr = Arc::clone(&scene);
let tile = Tile {
start_column: 0,
end_column: image_width,
start_row: 0,
end_row: image_height,
};
partial_render_scene(scene_ptr, tile, image_height, image_width);
}); });
b.iter(|| render_scene(output_image.clone(), scene.clone()));
} }
} }