mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
38 lines
1.2 KiB
Rust
38 lines
1.2 KiB
Rust
use criterion::{black_box, criterion_group, criterion_main, BatchSize, Benchmark, Criterion};
|
|
use veloren_world::layer::tree::{ProceduralTree, TreeConfig};
|
|
|
|
fn tree(c: &mut Criterion) {
|
|
c.bench_function("generate", |b| {
|
|
let mut i = 0;
|
|
b.iter(|| {
|
|
i += 1;
|
|
black_box(ProceduralTree::generate(TreeConfig::OAK, i));
|
|
});
|
|
});
|
|
|
|
c.bench_function("sample", |b| {
|
|
let mut i = 0;
|
|
b.iter_batched(
|
|
|| {
|
|
i += 1;
|
|
ProceduralTree::generate(TreeConfig::OAK, i)
|
|
},
|
|
|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);
|