add benchmark of SdfMeanDownsampler on a ChunkPyramid
use building_blocks_core::prelude::*;
-use building_blocks_storage::{Array3, ChunkDownsampler, Local, PointDownsampler};
+use building_blocks_storage::{
+ Array3, ChunkDownsampler, ChunkHashMapPyramid3, ChunkMapBuilder3, Local, OctreeChunkIndex,
+ PointDownsampler, Sd8, SdfMeanDownsampler,
+};
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
@@ -26,7 +29,55 @@ fn point_downsample3(c: &mut Criterion) {
group.finish();
}
-criterion_group!(benches, point_downsample3);
+fn sdf_mean_downsample_chunk_pyramid(c: &mut Criterion) {
+ let mut group = c.benchmark_group("sdf_mean_downsample_chunk_pyramid_all_lods");
+ for map_chunks in [1, 2, 4, 8].iter() {
+ group.bench_with_input(
+ BenchmarkId::from_parameter(map_chunks),
+ map_chunks,
+ |b, &map_chunks| {
+ b.iter_with_setup(
+ || {
+ let num_lods = 6;
+ let chunk_shape = PointN([16; 3]);
+ let superchunk_shape = PointN([(1 << num_lods) * 16; 3]);
+
+ let builder = ChunkMapBuilder3 {
+ chunk_shape,
+ ambient_value: Sd8::ONE,
+ default_chunk_metadata: (),
+ };
+ let mut lod0_map = builder.build_with_hash_map_storage();
+
+ let map_extent =
+ Extent3i::from_min_and_shape(Point3i::ZERO, Point3i::fill(map_chunks))
+ * chunk_shape;
+ lod0_map.fill_extent(&map_extent, Sd8::NEG_ONE);
+
+ let index = OctreeChunkIndex::index_chunk_map(superchunk_shape, &lod0_map);
+ let pyramid = ChunkHashMapPyramid3::with_lod0_chunk_map(lod0_map, num_lods);
+
+ (pyramid, index, map_extent)
+ },
+ |(mut pyramid, index, map_extent)| {
+ pyramid.downsample_chunks_for_extent_all_lods_with_index(
+ &index,
+ &SdfMeanDownsampler,
+ &map_extent,
+ )
+ },
+ );
+ },
+ );
+ }
+ group.finish();
+}
+
+criterion_group!(
+ benches,
+ point_downsample3,
+ sdf_mean_downsample_chunk_pyramid
+);
criterion_main!(benches);
const CHUNK_SIZES: [i32; 3] = [16, 32, 64];
