e6fb210c3b
# Conflicts: # src/main.rs
37 lines
1.0 KiB
Rust
37 lines
1.0 KiB
Rust
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;
|
|
|
|
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;
|
|
|
|
data[X][Y][Z]
|
|
}
|
|
|
|
fn voxel_map_benchmark(c: &mut Criterion) {
|
|
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()))));
|
|
}
|
|
|
|
criterion_group!(benches, voxel_map_benchmark);
|
|
criterion_main!(benches); |