2023-09-16 09:28:05 +02:00
|
|
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
|
|
|
|
|
|
|
const MAP_WIDTH: usize = 100;
|
|
|
|
const MAP_HEIGHT: usize = 100;
|
|
|
|
const MAP_DEPTH: usize = 100;
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
|
|
struct Voxel {
|
|
|
|
r: u8, g: u8, b: u8
|
|
|
|
}
|
|
|
|
|
|
|
|
fn voxel_vec_1d(data: Vec<Voxel>) -> Voxel {
|
|
|
|
const X: usize = 0;
|
|
|
|
const Y: usize = 0;
|
|
|
|
const Z: usize = 0;
|
|
|
|
|
|
|
|
return data[X + Y * MAP_WIDTH + Z * MAP_WIDTH * MAP_HEIGHT];
|
|
|
|
}
|
|
|
|
|
|
|
|
fn voxel_vec_3d(data: Vec<Vec<Vec<Voxel>>>) -> Voxel {
|
|
|
|
const X: usize = 0;
|
|
|
|
const Y: usize = 0;
|
|
|
|
const Z: usize = 0;
|
|
|
|
|
|
|
|
return data[X][Y][Z];
|
|
|
|
}
|
|
|
|
|
2023-09-16 10:32:16 +02:00
|
|
|
fn voxel_map_benchmark(c: &mut Criterion) {
|
2023-09-16 09:28:05 +02:00
|
|
|
let vec_1d = vec![Voxel { r: 0, g: 0, b: 0 }; MAP_WIDTH * MAP_HEIGHT * MAP_DEPTH];
|
|
|
|
let vec_3d = vec![vec![vec![Voxel { r: 0, g: 0, b: 0 }; MAP_DEPTH]; MAP_HEIGHT]; MAP_WIDTH];
|
|
|
|
|
|
|
|
c.bench_function("voxels in 1d vector", |b| b.iter(|| voxel_vec_1d(black_box(vec_1d.clone()))));
|
|
|
|
c.bench_function("voxels in 3d vector", |b| b.iter(|| voxel_vec_3d(black_box(vec_3d.clone()))));
|
|
|
|
}
|
|
|
|
|
2023-09-16 10:32:16 +02:00
|
|
|
criterion_group!(benches, voxel_map_benchmark);
|
2023-09-16 09:28:05 +02:00
|
|
|
criterion_main!(benches);
|