aboutsummaryrefslogtreecommitdiff
path: root/azalea-world/benches
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2026-02-18 19:23:05 -1200
committermat <git@matdoes.dev>2026-02-18 19:23:05 -1200
commit50119ac97a36d94ab9bb5bd2d8c31d1d0c494a48 (patch)
tree1b4b3faea36d5b2aed9b02a87844843659bc5c5c /azalea-world/benches
parent03344135d544440321b1cc1915c04492b727e76f (diff)
downloadazalea-drasl-50119ac97a36d94ab9bb5bd2d8c31d1d0c494a48.tar.xz
simplify bit storage
Diffstat (limited to 'azalea-world/benches')
-rw-r--r--azalea-world/benches/chunks.rs37
1 files changed, 30 insertions, 7 deletions
diff --git a/azalea-world/benches/chunks.rs b/azalea-world/benches/chunks.rs
index 64924fec..e1ca94a6 100644
--- a/azalea-world/benches/chunks.rs
+++ b/azalea-world/benches/chunks.rs
@@ -3,7 +3,7 @@ use std::hint::black_box;
use azalea_core::position::ChunkBlockPos;
use azalea_registry::builtin::BlockKind;
use azalea_world::{BitStorage, Chunk};
-use criterion::{Criterion, criterion_group, criterion_main};
+use criterion::{BatchSize, Bencher, Criterion, criterion_group, criterion_main};
fn bench_chunks(c: &mut Criterion) {
c.bench_function("Chunk::set", |b| {
@@ -25,13 +25,36 @@ fn bench_chunks(c: &mut Criterion) {
});
}
+fn bench_bitstorage_with(b: &mut Bencher, bits: usize, size: usize) {
+ let mut storage = BitStorage::new(bits, size, None).unwrap();
+ b.iter_batched(
+ || {
+ // let index = rand
+ let mut vec = Vec::with_capacity(size);
+ for _ in 0..size {
+ vec.push(rand::random_range(0..size));
+ }
+ vec
+ },
+ |indices| {
+ for index in indices {
+ storage.set(index, 1);
+ }
+ },
+ BatchSize::SmallInput,
+ );
+ black_box(storage);
+}
+
fn bench_bitstorage(c: &mut Criterion) {
- c.bench_function("BitStorage::set", |b| {
- let mut storage = BitStorage::new(1, 4096, None).unwrap();
- b.iter(|| {
- storage.set(136, 1);
- });
- black_box(storage);
+ c.bench_function("BitStorage::set (1 bit per entry)", |b| {
+ bench_bitstorage_with(b, 1, 4096)
+ });
+ c.bench_function("BitStorage::set (2 bits per entry)", |b| {
+ bench_bitstorage_with(b, 2, 4096)
+ });
+ c.bench_function("BitStorage::set (3 bits per entry)", |b| {
+ bench_bitstorage_with(b, 3, 4096)
});
}