2021-03-06 17:23:03 +00:00
|
|
|
use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion};
|
|
|
|
use rand::prelude::*;
|
2021-01-06 02:19:35 +00:00
|
|
|
use veloren_world::layer::tree::{ProceduralTree, TreeConfig};
|
2021-01-05 19:04:16 +00:00
|
|
|
|
|
|
|
fn tree(c: &mut Criterion) {
|
|
|
|
c.bench_function("generate", |b| {
|
|
|
|
let mut i = 0;
|
|
|
|
b.iter(|| {
|
|
|
|
i += 1;
|
2021-03-06 17:23:03 +00:00
|
|
|
black_box(ProceduralTree::generate(
|
|
|
|
TreeConfig::oak(&mut thread_rng(), 1.0),
|
|
|
|
&mut thread_rng(),
|
|
|
|
));
|
2021-01-05 19:04:16 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
c.bench_function("sample", |b| {
|
|
|
|
let mut i = 0;
|
|
|
|
b.iter_batched(
|
2021-01-06 02:19:35 +00:00
|
|
|
|| {
|
|
|
|
i += 1;
|
2021-03-06 17:23:03 +00:00
|
|
|
ProceduralTree::generate(TreeConfig::oak(&mut thread_rng(), 1.0), &mut thread_rng())
|
2021-01-06 02:19:35 +00:00
|
|
|
},
|
2021-01-05 19:04:16 +00:00
|
|
|
|tree| {
|
|
|
|
let bounds = tree.get_bounds();
|
|
|
|
for x in (bounds.min.x as i32..bounds.max.x as i32).step_by(3) {
|
|
|
|
for y in (bounds.min.y as i32..bounds.max.y as i32).step_by(3) {
|
|
|
|
for z in (bounds.min.z as i32..bounds.max.z as i32).step_by(3) {
|
|
|
|
let pos = (x as f32, y as f32, z as f32).into();
|
|
|
|
black_box(tree.is_branch_or_leaves_at(pos));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
BatchSize::SmallInput,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(benches, tree);
|
|
|
|
criterion_main!(benches);
|