Skip to content

Commit

Permalink
Make Perlin benches use core functions
Browse files Browse the repository at this point in the history
Also make Vectors pub to use in benches
  • Loading branch information
Cifram authored and Razaekel committed Apr 13, 2023
1 parent 88d0665 commit f388bea
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
41 changes: 28 additions & 13 deletions benches/perlin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ extern crate criterion;
extern crate noise;

use criterion::{black_box, Criterion};
use noise::{NoiseFn, Perlin};
use noise::{
core::perlin::{perlin_2d, perlin_3d, perlin_4d},
permutationtable::PermutationTable,
Vector2, Vector3, Vector4,
};

criterion_group!(perlin, bench_perlin2, bench_perlin3, bench_perlin4);
criterion_group!(
Expand All @@ -15,59 +19,70 @@ criterion_group!(
criterion_main!(perlin, perlin_64x64);

fn bench_perlin2(c: &mut Criterion) {
let perlin = Perlin::default();
let hasher = PermutationTable::new(0);
c.bench_function("perlin 2d", |b| {
b.iter(|| perlin.get(black_box([42.0_f64, 37.0])))
b.iter(|| perlin_2d(black_box(Vector2::new(42.0_f64, 37.0)), &hasher))
});
}

fn bench_perlin3(c: &mut Criterion) {
let perlin = Perlin::default();
let hasher = PermutationTable::new(0);
c.bench_function("perlin 3d", |b| {
b.iter(|| perlin.get(black_box([42.0_f64, 37.0, 26.0])))
b.iter(|| perlin_3d(black_box(Vector3::new(42.0_f64, 37.0, 26.0)), &hasher))
});
}

fn bench_perlin4(c: &mut Criterion) {
let perlin = Perlin::default();
let hasher = PermutationTable::new(0);
c.bench_function("perlin 4d", |b| {
b.iter(|| perlin.get(black_box([42.0_f64, 37.0, 26.0, 128.0])))
b.iter(|| {
perlin_4d(
black_box(Vector4::new(42.0_f64, 37.0, 26.0, 128.0)),
&hasher,
)
})
});
}

fn bench_perlin2_64x64(c: &mut Criterion) {
let perlin = Perlin::default();
let hasher = PermutationTable::new(0);
c.bench_function("perlin 2d (64x64)", |b| {
b.iter(|| {
for y in 0i8..64 {
for x in 0i8..64 {
black_box(perlin.get([x as f64, y as f64]));
perlin_2d(black_box(Vector2::new(x as f64, y as f64)), &hasher);
}
}
})
});
}

fn bench_perlin3_64x64(c: &mut Criterion) {
let perlin = Perlin::default();
let hasher = PermutationTable::new(0);
c.bench_function("perlin 3d (64x64)", |b| {
b.iter(|| {
for y in 0i8..64 {
for x in 0i8..64 {
black_box(perlin.get([x as f64, y as f64, x as f64]));
perlin_3d(
black_box(Vector3::new(x as f64, y as f64, x as f64)),
&hasher,
);
}
}
})
});
}

fn bench_perlin4_64x64(c: &mut Criterion) {
let perlin = Perlin::default();
let hasher = PermutationTable::new(0);
c.bench_function("perlin 4d (64x64)", |b| {
b.iter(|| {
for y in 0i8..64 {
for x in 0i8..64 {
black_box(perlin.get([x as f64, y as f64, x as f64, y as f64]));
perlin_4d(
black_box(Vector4::new(x as f64, y as f64, x as f64, y as f64)),
&hasher,
);
}
}
})
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
#[macro_use]
extern crate alloc;

pub use crate::math::vectors::*;
pub use crate::noise_fns::*;

pub mod core;
mod gradient;
mod math;
pub mod math;
mod noise_fns;
pub mod permutationtable;
pub mod utils;
2 changes: 1 addition & 1 deletion src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

pub(crate) mod interpolate;
pub(crate) mod s_curve;
pub(crate) mod vectors;
pub mod vectors;

#[cfg(not(target_os = "emscripten"))]
#[inline]
Expand Down

0 comments on commit f388bea

Please sign in to comment.