-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from Walther/2024-02-03
2024-02-03 improvements
- Loading branch information
Showing
11 changed files
with
353 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
use std::f32::{INFINITY, NEG_INFINITY}; | ||
|
||
use clovers::interval::Interval; | ||
use clovers::ray::Ray; | ||
use clovers::wavelength::random_wavelength; | ||
use clovers::{aabb::*, Vec3}; | ||
use divan::black_box; | ||
use rand::rngs::SmallRng; | ||
use rand::{Rng, SeedableRng}; | ||
|
||
fn main() { | ||
divan::main(); | ||
} | ||
|
||
#[divan::bench] | ||
fn new(bencher: divan::Bencher) { | ||
bencher | ||
.with_inputs(|| { | ||
let mut rng = SmallRng::from_entropy(); | ||
random_intervals(&mut rng) | ||
}) | ||
.bench_values(|(ab, cd, ef)| black_box(AABB::new(ab, cd, ef))) | ||
} | ||
|
||
#[divan::bench] | ||
fn hit(bencher: divan::Bencher) { | ||
bencher | ||
.with_inputs(random_aabb_and_ray) | ||
.bench_values(|(aabb, ray)| black_box(aabb.hit(&ray, NEG_INFINITY, INFINITY))) | ||
} | ||
|
||
#[divan::bench] | ||
fn hit_old(bencher: divan::Bencher) { | ||
bencher | ||
.with_inputs(random_aabb_and_ray) | ||
.bench_values(|(aabb, ray)| { | ||
#[allow(deprecated)] | ||
black_box(aabb.hit_old(&ray, NEG_INFINITY, INFINITY)) | ||
}) | ||
} | ||
|
||
#[divan::bench] | ||
fn hit_new(bencher: divan::Bencher) { | ||
bencher | ||
.with_inputs(random_aabb_and_ray) | ||
.bench_values(|(aabb, ray)| { | ||
#[allow(deprecated)] | ||
black_box(aabb.hit_new(&ray, NEG_INFINITY, INFINITY)) | ||
}) | ||
} | ||
|
||
// Helper functions | ||
|
||
fn random_intervals(rng: &mut SmallRng) -> (Interval, Interval, Interval) { | ||
let (a, b, c, d, e, f) = black_box(( | ||
rng.gen(), | ||
rng.gen(), | ||
rng.gen(), | ||
rng.gen(), | ||
rng.gen(), | ||
rng.gen(), | ||
)); | ||
let ab = Interval::new(a, b); | ||
let cd = Interval::new(c, d); | ||
let ef = Interval::new(e, f); | ||
(ab, cd, ef) | ||
} | ||
|
||
fn random_aabb(rng: &mut SmallRng) -> AABB { | ||
let (ab, cd, ef) = random_intervals(rng); | ||
black_box(AABB::new(ab, cd, ef)) | ||
} | ||
|
||
fn random_ray(rng: &mut SmallRng) -> Ray { | ||
black_box(Ray { | ||
origin: Vec3::new(0.0, 0.0, 0.0), | ||
direction: Vec3::new(rng.gen(), rng.gen(), rng.gen()), | ||
time: rng.gen(), | ||
wavelength: random_wavelength(rng), | ||
}) | ||
} | ||
|
||
fn random_aabb_and_ray() -> (AABB, Ray) { | ||
let mut rng = SmallRng::from_entropy(); | ||
let aabb = black_box(random_aabb(&mut rng)); | ||
let ray = black_box(random_ray(&mut rng)); | ||
(aabb, ray) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use clovers::interval::*; | ||
use divan::black_box; | ||
use rand::rngs::SmallRng; | ||
use rand::{Rng, SeedableRng}; | ||
|
||
fn main() { | ||
divan::main(); | ||
} | ||
|
||
#[divan::bench] | ||
fn new(bencher: divan::Bencher) { | ||
bencher | ||
.with_inputs(|| { | ||
let mut rng = SmallRng::from_entropy(); | ||
(rng.gen(), rng.gen()) | ||
}) | ||
.bench_values(|(a, b)| black_box(Interval::new(a, b))) | ||
} | ||
|
||
#[divan::bench] | ||
fn new_from_intervals(bencher: divan::Bencher) { | ||
bencher | ||
.with_inputs(|| { | ||
let mut rng = SmallRng::from_entropy(); | ||
let ab = random_interval(&mut rng); | ||
let cd = random_interval(&mut rng); | ||
(ab, cd) | ||
}) | ||
.bench_values(|(ab, cd)| black_box(Interval::new_from_intervals(ab, cd))) | ||
} | ||
|
||
#[divan::bench] | ||
fn expand(bencher: divan::Bencher) { | ||
bencher | ||
.with_inputs(|| { | ||
let mut rng = SmallRng::from_entropy(); | ||
let ab = random_interval(&mut rng); | ||
let delta = rng.gen(); | ||
(ab, delta) | ||
}) | ||
.bench_values(|(ab, delta)| black_box(ab.expand(delta))) | ||
} | ||
|
||
#[divan::bench] | ||
fn size(bencher: divan::Bencher) { | ||
bencher | ||
.with_inputs(|| { | ||
let mut rng = SmallRng::from_entropy(); | ||
random_interval(&mut rng) | ||
}) | ||
.bench_values(|ab| black_box(ab.size())) | ||
} | ||
|
||
// Helper functions | ||
|
||
fn random_interval(rng: &mut SmallRng) -> Interval { | ||
let (a, b) = (rng.gen(), rng.gen()); | ||
Interval::new(a, b) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,39 @@ | ||
use clovers::{random::*, Vec3}; | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use divan::black_box; | ||
use rand::rngs::SmallRng; | ||
#[allow(unused_imports)] | ||
use rand::SeedableRng; | ||
|
||
pub fn criterion_benchmark(c: &mut Criterion) { | ||
let mut rng = SmallRng::from_entropy(); | ||
|
||
c.bench_function("random in unit sphere", |b| { | ||
b.iter(|| random_unit_vector(black_box(&mut rng))) | ||
}); | ||
|
||
c.bench_function("random in unit disk", |b| { | ||
b.iter(|| random_in_unit_disk(black_box(&mut rng))) | ||
}); | ||
fn main() { | ||
divan::main(); | ||
} | ||
|
||
c.bench_function("random unit vector", |b| { | ||
b.iter(|| random_unit_vector(black_box(&mut rng))) | ||
}); | ||
#[divan::bench] | ||
fn unit_vector(bencher: divan::Bencher) { | ||
bencher | ||
.with_inputs(SmallRng::from_entropy) | ||
.bench_values(|mut rng| random_unit_vector(black_box(&mut rng))) | ||
} | ||
|
||
c.bench_function("random cosine direction", |b| { | ||
b.iter(|| random_cosine_direction(black_box(&mut rng))) | ||
}); | ||
#[divan::bench] | ||
fn unit_disk(bencher: divan::Bencher) { | ||
bencher | ||
.with_inputs(SmallRng::from_entropy) | ||
.bench_values(|mut rng| random_in_unit_disk(black_box(&mut rng))) | ||
} | ||
|
||
let normal = Vec3::new(1.0, 0.0, 0.0); | ||
c.bench_function("random in hemisphere", |b| { | ||
b.iter(|| random_on_hemisphere(normal, black_box(&mut rng))) | ||
}); | ||
#[divan::bench] | ||
fn cosine_direction(bencher: divan::Bencher) { | ||
bencher | ||
.with_inputs(SmallRng::from_entropy) | ||
.bench_values(|mut rng| random_cosine_direction(black_box(&mut rng))) | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); | ||
#[divan::bench] | ||
fn hemisphere(bencher: divan::Bencher) { | ||
bencher | ||
.with_inputs(SmallRng::from_entropy) | ||
.bench_values(|mut rng| { | ||
let normal = Vec3::new(1.0, 0.0, 0.0); | ||
random_on_hemisphere(normal, black_box(&mut rng)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use clovers::spectrum::*; | ||
use clovers::wavelength::*; | ||
use divan::black_box; | ||
use palette::white_point::E; | ||
use palette::Xyz; | ||
use rand::rngs::SmallRng; | ||
use rand::SeedableRng; | ||
|
||
fn main() { | ||
divan::main(); | ||
} | ||
|
||
#[divan::bench] | ||
fn xyz_to_p(bencher: divan::Bencher) { | ||
bencher | ||
.with_inputs(|| { | ||
let mut rng = SmallRng::from_entropy(); | ||
let wave = random_wavelength(&mut rng); | ||
let xyz: Xyz<E> = Xyz::new(1.0, 1.0, 1.0); | ||
(wave, xyz) | ||
}) | ||
.bench_values(|(wave, xyz)| black_box(spectrum_xyz_to_p(wave, xyz))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use clovers::wavelength::*; | ||
use divan::black_box; | ||
use rand::rngs::SmallRng; | ||
use rand::SeedableRng; | ||
|
||
fn main() { | ||
divan::main(); | ||
} | ||
|
||
#[divan::bench] | ||
fn random(bencher: divan::Bencher) { | ||
bencher | ||
.with_inputs(SmallRng::from_entropy) | ||
.bench_values(|mut rng| black_box(random_wavelength(&mut rng))) | ||
} | ||
|
||
#[divan::bench] | ||
fn rotate(bencher: divan::Bencher) { | ||
bencher | ||
.with_inputs(|| { | ||
let mut rng = SmallRng::from_entropy(); | ||
random_wavelength(&mut rng) | ||
}) | ||
.bench_values(|wave| black_box(rotate_wavelength(wave))) | ||
} | ||
|
||
#[divan::bench] | ||
fn into_xyz(bencher: divan::Bencher) { | ||
bencher | ||
.with_inputs(|| { | ||
let mut rng = SmallRng::from_entropy(); | ||
random_wavelength(&mut rng) | ||
}) | ||
.bench_values(|wave| black_box(wavelength_into_xyz(wave))) | ||
} |
Oops, something went wrong.