From e4b99ded927863875c17119c307461124565ae2a Mon Sep 17 00:00:00 2001 From: Mili Date: Mon, 3 Mar 2025 13:07:35 +0000 Subject: [PATCH] refactor: replace hardcoded channel size with a constant, print seed used, add one more size to bench. --- pumpkin-world/benches/chunk_noise_populate.rs | 52 +++++++++++++------ 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/pumpkin-world/benches/chunk_noise_populate.rs b/pumpkin-world/benches/chunk_noise_populate.rs index 147470135..9b8a4da9a 100644 --- a/pumpkin-world/benches/chunk_noise_populate.rs +++ b/pumpkin-world/benches/chunk_noise_populate.rs @@ -1,10 +1,10 @@ -use std::{fs, num::NonZeroU8, path::PathBuf, sync::Arc}; +use std::{fs, path::PathBuf, sync::Arc}; use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main}; use pumpkin_util::math::vector2::Vector2; use pumpkin_world::{ GlobalProtoNoiseRouter, GlobalRandomConfig, NOISE_ROUTER_ASTS, bench_create_and_populate_noise, - chunk::ChunkData, cylindrical_chunk_iterator::Cylindrical, global_path, level::Level, + chunk::ChunkData, global_path, level::Level, }; use tokio::sync::RwLock; @@ -22,7 +22,7 @@ fn bench_populate_noise(c: &mut Criterion) { async fn test_reads(root_dir: PathBuf, positions: Vec>) { let level = Arc::new(Level::from_root_folder(root_dir)); - let (send, mut recv) = tokio::sync::mpsc::channel(positions.len()); + let (send, mut recv) = tokio::sync::mpsc::channel(CHANNEL_SIZE); tokio::spawn(async move { level.fetch_chunks(&positions, send).await }); while let Some(x) = recv.recv().await { @@ -37,6 +37,12 @@ async fn test_writes(root_dir: PathBuf, chunks: Vec<(Vector2, Arc>(); + level_to_fetch.fetch_chunks(&chunks_to_generate, send).await; }); + while let Some((chunk, _)) = recv.recv().await { let pos = chunk.read().await.position; chunks.push((pos, chunk)); positions.push(pos); } + level_to_save.write_chunks(chunks.clone()).await; }); // Sort by distance from origin to ensure a fair selection // when using a subset of the total chunks for the benchmarks - chunks.sort_unstable_by_key(|chunk| chunk.0.x * chunk.0.x + chunk.0.z * chunk.0.z); - positions.sort_unstable_by_key(|pos| pos.x * pos.x + pos.z * pos.z); + chunks.sort_unstable_by_key(|chunk| (chunk.0.x * chunk.0.x) + (chunk.0.z * chunk.0.z)); + positions.sort_unstable_by_key(|pos| (pos.x * pos.x) + (pos.z * pos.z)); // These test worst case: no caching done by `Level` // testing with 16, 64, 256 chunks let mut write_group = c.benchmark_group("write_chunks"); - for n_chunks in [16, 64, 256] { + for n_chunks in [16, 64, 256, 512] { let chunks = &chunks[..n_chunks]; - println!("Testing with {} chunks", n_chunks); + assert!( + chunks.len() == n_chunks, + "Expected {} chunks, got {}", + n_chunks, + chunks.len() + ); write_group.bench_with_input( BenchmarkId::from_parameter(n_chunks), &chunks, @@ -95,9 +112,14 @@ fn bench_chunk_io(c: &mut Criterion) { // These test worst case: no caching done by `Level` // testing with 16, 64, 256 chunks let mut read_group = c.benchmark_group("read_chunks"); - for n_chunks in [16, 64, 256] { + for n_chunks in [16, 64, 256, 512] { let positions = &positions[..n_chunks]; - println!("Testing with {} chunks", n_chunks); + assert!( + positions.len() == n_chunks, + "Expected {} chunks, got {}", + n_chunks, + positions.len() + ); read_group.bench_with_input( BenchmarkId::from_parameter(n_chunks),