diff --git a/pumpkin-world/Cargo.toml b/pumpkin-world/Cargo.toml index 252798726..0b72e8aba 100644 --- a/pumpkin-world/Cargo.toml +++ b/pumpkin-world/Cargo.toml @@ -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 diff --git a/pumpkin-world/benches/chunk_io.rs b/pumpkin-world/benches/chunk_io.rs new file mode 100644 index 000000000..f9375075f --- /dev/null +++ b/pumpkin-world/benches/chunk_io.rs @@ -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);