Skip to content

Commit ab31f46

Browse files
committed
Add benchmark with 100 spheres.
1 parent 4f69663 commit ab31f46

File tree

3 files changed

+867
-1
lines changed

3 files changed

+867
-1
lines changed

Cargo.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,23 @@ edition = "2018"
99
[lib]
1010
name = "rusttracer"
1111
path = "src/lib.rs"
12+
bench = false
1213

1314
[[bin]]
1415
name = "rusttracer-bin"
1516
path = "src/main.rs"
17+
bench = false
1618

1719
[dependencies]
1820
overload = "0.1.1"
1921
image = "0.23.12"
2022
rand = "0.7.3"
2123
rayon = "1.5.0"
22-
num = "0.3.1"
24+
num = "0.3.1"
25+
26+
[dev-dependencies]
27+
criterion = "0.3.3"
28+
29+
[[bench]]
30+
name = "100scene"
31+
harness = false

benches/100scene.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2+
3+
use rusttracer::structs::vec3::Vec3;
4+
use rusttracer::structs::viewport::Viewport;
5+
6+
fn setup_and_run(samples: u32) -> Vec<u8> {
7+
let aspect_ratio = 16. / 9.;
8+
let img_width = 1200u32;
9+
let img_height = (img_width as f64 / aspect_ratio) as u32;
10+
let ray_depth = 50;
11+
12+
let lookfrom = Vec3::new(8., 2., 2.);
13+
let lookat = Vec3::new(0., 0., 0.);
14+
let vup = Vec3::new(0., 1., 0.);
15+
let dist_to_focus = (lookfrom - lookat).length();
16+
let aperture = 0.1;
17+
let vertical_fov = 60.;
18+
19+
let viewport = Viewport::new(
20+
lookfrom,
21+
lookat,
22+
vup,
23+
vertical_fov,
24+
aspect_ratio,
25+
aperture,
26+
dist_to_focus,
27+
);
28+
29+
viewport.render(
30+
img_width,
31+
img_height,
32+
samples,
33+
ray_depth,
34+
rusttracer::benchmarking_scene(),
35+
)
36+
}
37+
38+
pub fn criterion_benchmark(c: &mut Criterion) {
39+
c.bench_function("100scene", |b| b.iter(|| setup_and_run(black_box(10))));
40+
}
41+
42+
criterion_group!(benches, criterion_benchmark);
43+
criterion_main!(benches);

0 commit comments

Comments
 (0)