Skip to content

Commit

Permalink
feat: add intial benchmark for chunk I/O performance and update crite…
Browse files Browse the repository at this point in the history
…rion dependencies
  • Loading branch information
Mili committed Mar 1, 2025
1 parent ad87181 commit 9e510d9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pumpkin-world/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ serde_json5 = { git = "https://github.com/kralverde/serde_json5.git" }

derive-getters = "0.5.0"
[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] }
criterion = { version = "0.5", features = ["html_reports", "async_tokio"] }
temp-dir = "0.1.14"

[[bench]]
name = "chunk_noise_populate"
harness = false

[[bench]]
name = "chunk_io"
harness = false
32 changes: 32 additions & 0 deletions pumpkin-world/benches/chunk_io.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use std::{num::NonZeroU8, sync::Arc};

use criterion::{Criterion, criterion_group, criterion_main};
use pumpkin_util::math::vector2::Vector2;
use pumpkin_world::{cylindrical_chunk_iterator::Cylindrical, dimension::Dimension};
use temp_dir::TempDir;

fn criterion_benchmark(c: &mut Criterion) {
let temp_dir = TempDir::new().unwrap();
let level = Arc::new(Dimension::OverWorld.into_level(temp_dir.path().to_path_buf()));

c.bench_function("overworld chunk fetch", |b| {
let rt = tokio::runtime::Runtime::new().unwrap();
let cylindrical = Cylindrical::new(Vector2::new(0, 0), NonZeroU8::new(32).unwrap());
let chunks = cylindrical.all_chunks_within();

rt.block_on(async {
let (tx, _rx) = tokio::sync::mpsc::channel(chunks.len());
level.fetch_chunks(&chunks, tx).await;
level.clean_chunks(&chunks).await;
});

b.to_async(rt).iter(|| {
let (tx, _rx) = tokio::sync::mpsc::channel(chunks.len());

level.fetch_chunks(&chunks, tx)
});
});
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

0 comments on commit 9e510d9

Please sign in to comment.