benchmark

This commit is contained in:
StephenAdamson
2025-02-06 21:32:30 +00:00
parent 6161c21e22
commit 4089851734
5 changed files with 246 additions and 28 deletions
Generated
+99 -18
View File
@@ -75,10 +75,10 @@ checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011"
dependencies = [
"cfg-if",
"const-random",
"getrandom",
"getrandom 0.2.15",
"once_cell",
"version_check",
"zerocopy",
"zerocopy 0.7.35",
]
[[package]]
@@ -786,7 +786,7 @@ dependencies = [
"derive_more",
"glam",
"itertools",
"rand",
"rand 0.8.5",
"rand_distr",
"serde",
"smallvec",
@@ -1164,7 +1164,7 @@ checksum = "4f01088c048960ea50ee847c3f668942ecf49ed26be12a1585a5e59b6a941d9a"
dependencies = [
"ahash",
"bevy_utils_proc_macros",
"getrandom",
"getrandom 0.2.15",
"hashbrown 0.14.5",
"thread_local",
"tracing",
@@ -1512,7 +1512,7 @@ version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e"
dependencies = [
"getrandom",
"getrandom 0.2.15",
"once_cell",
"tiny-keccak",
]
@@ -1794,7 +1794,7 @@ version = "0.1.0"
dependencies = [
"bevy",
"noise",
"rand",
"rand 0.9.0",
]
[[package]]
@@ -2070,10 +2070,22 @@ dependencies = [
"cfg-if",
"js-sys",
"libc",
"wasi",
"wasi 0.11.0+wasi-snapshot-preview1",
"wasm-bindgen",
]
[[package]]
name = "getrandom"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43a49c392881ce6d5c3b8cb70f98717b7c07aabbdff06687b9030dbfbe2725f8"
dependencies = [
"cfg-if",
"libc",
"wasi 0.13.3+wasi-0.2.2",
"windows-targets 0.52.6",
]
[[package]]
name = "gilrs"
version = "0.11.0"
@@ -2126,7 +2138,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc46dd3ec48fdd8e693a98d2b8bafae273a2d54c1de02a2a7e3d57d501f39677"
dependencies = [
"bytemuck",
"rand",
"rand 0.8.5",
"serde",
]
@@ -2726,7 +2738,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6da45c8333f2e152fc665d78a380be060eb84fad8ca4c9f7ac8ca29216cff0cc"
dependencies = [
"num-traits",
"rand",
"rand 0.8.5",
"rand_xorshift",
]
@@ -3221,7 +3233,7 @@ version = "0.2.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04"
dependencies = [
"zerocopy",
"zerocopy 0.7.35",
]
[[package]]
@@ -3286,8 +3298,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
"rand_chacha 0.3.1",
"rand_core 0.6.4",
]
[[package]]
name = "rand"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94"
dependencies = [
"rand_chacha 0.9.0",
"rand_core 0.9.0",
"zerocopy 0.8.16",
]
[[package]]
@@ -3297,7 +3320,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
"rand_core 0.6.4",
]
[[package]]
name = "rand_chacha"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
dependencies = [
"ppv-lite86",
"rand_core 0.9.0",
]
[[package]]
@@ -3306,7 +3339,17 @@ version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
"getrandom 0.2.15",
]
[[package]]
name = "rand_core"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b08f3c9802962f7e1b25113931d94f43ed9725bebc59db9d0c3e9a23b67e15ff"
dependencies = [
"getrandom 0.3.1",
"zerocopy 0.8.16",
]
[[package]]
@@ -3316,7 +3359,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32cb0b9bc82b0a0876c2dd994a7e7a2683d3e7390ca40e6886785ef0c7e3ee31"
dependencies = [
"num-traits",
"rand",
"rand 0.8.5",
]
[[package]]
@@ -3325,7 +3368,7 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f"
dependencies = [
"rand_core",
"rand_core 0.6.4",
]
[[package]]
@@ -3998,7 +4041,7 @@ version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a"
dependencies = [
"getrandom",
"getrandom 0.2.15",
"serde",
]
@@ -4036,6 +4079,15 @@ version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasi"
version = "0.13.3+wasi-0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26816d2e1a4a36a2940b96c5296ce403917633dff8f3440e9b236ed6f6bacad2"
dependencies = [
"wit-bindgen-rt",
]
[[package]]
name = "wasm-bindgen"
version = "0.2.99"
@@ -4655,6 +4707,15 @@ dependencies = [
"memchr",
]
[[package]]
name = "wit-bindgen-rt"
version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3268f3d866458b787f390cf61f4bbb563b922d091359f9608842999eaee3943c"
dependencies = [
"bitflags 2.6.0",
]
[[package]]
name = "x11-dl"
version = "2.21.0"
@@ -4731,7 +4792,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
dependencies = [
"byteorder",
"zerocopy-derive",
"zerocopy-derive 0.7.35",
]
[[package]]
name = "zerocopy"
version = "0.8.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b8c07a70861ce02bad1607b5753ecb2501f67847b9f9ada7c160fff0ec6300c"
dependencies = [
"zerocopy-derive 0.8.16",
]
[[package]]
@@ -4744,3 +4814,14 @@ dependencies = [
"quote",
"syn",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5226bc9a9a9836e7428936cde76bb6b22feea1a8bfdbc0d241136e4d13417e25"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
+1 -1
View File
@@ -6,7 +6,7 @@ edition = "2021"
[dependencies]
bevy = "0.15.1"
noise = "0.9.0"
rand = "0.8.5"
rand = "0.9.0"
# Enable max optimizations for dependencies, but not for our code:
[profile.dev.package."*"]
+6 -3
View File
@@ -34,7 +34,10 @@ impl Citizen {
use crate::constants::TILE_SIZE;
use crate::tile::TileMap;
use rand::{seq::SliceRandom, Rng};
use rand::{
seq::{IndexedRandom, SliceRandom},
Rng,
};
use std::{
collections::{BinaryHeap, HashMap, HashSet},
process::exit,
@@ -83,7 +86,7 @@ pub fn update_citizen_wandering_targets(
tilemap: Res<TileMap>,
chunk_map: Res<ChunkMap>,
) {
let mut rng: rand::prelude::ThreadRng = rand::thread_rng();
let mut rng: rand::prelude::ThreadRng = rand::rng();
for (mut ambulatory, _) in query.iter_mut() {
if ambulatory.target.is_none()
@@ -337,7 +340,7 @@ fn reconstruct_path(came_from: HashMap<IVec3, IVec3>, mut current: IVec3) -> Vec
}
pub fn spawn_citizens(mut commands: Commands, asset_server: Res<AssetServer>) {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
// Spawn a handful of citizens
for _ in 0..5 {
+138 -4
View File
@@ -1,4 +1,9 @@
use std::fs::File;
use bevy::prelude::*;
use bevy::window::WindowMode;
use std::io::Write;
use tile::CameraMoved;
mod camera;
mod citizen;
@@ -21,6 +26,8 @@ fn main() {
.set(WindowPlugin {
primary_window: Some(Window {
title: String::from("Dorf"),
resizable: false,
mode: WindowMode::BorderlessFullscreen(MonitorSelection::Primary),
..Default::default()
}),
..Default::default()
@@ -42,7 +49,7 @@ fn main() {
.add_systems(
FixedUpdate,
(
camera::camera_movement,
// camera::camera_movement,
cursor::move_cursor,
// citizen::check_citizen_positions_for_chunks,
),
@@ -51,10 +58,20 @@ fn main() {
.add_systems(
Update,
(
tile::camera_z_movement,
// tile::camera_z_movement,
tile::update_tile_visibility
.run_if(|camera_moved: Res<tile::CameraMoved>| camera_moved.0),
// log_fps_system,
),
)
.init_resource::<DiagnosticsRecorder>()
.add_systems(
Update,
(
start_recording_system,
record_diagnostics_system,
tile::update_tile_visibility
.run_if(|camera_moved: Res<tile::CameraMoved>| camera_moved.0),
log_fps_system,
),
)
.run();
@@ -68,6 +85,123 @@ fn log_fps_system(diagnostics: Res<DiagnosticsStore>) {
.get(&FrameTimeDiagnosticsPlugin::FPS)
.and_then(|fps_diagnostic| fps_diagnostic.average())
{
println!("Average FPS: {:.2}", fps);
println!("Average FPS: {:?}", fps);
}
if let Some(instantaneous_fps) = diagnostics
.get(&FrameTimeDiagnosticsPlugin::FPS)
.and_then(|fps_diagnostic| fps_diagnostic.value())
{
println!("Instantaneous FPS: {:?}", instantaneous_fps);
}
if let Some(ft) = diagnostics
.get(&FrameTimeDiagnosticsPlugin::FRAME_TIME)
.and_then(|fps_diagnostic| fps_diagnostic.average())
{
println!("Average FT: {:?}", ft);
}
if let Some(instantaneous_ft) = diagnostics
.get(&FrameTimeDiagnosticsPlugin::FRAME_TIME)
.and_then(|fps_diagnostic| fps_diagnostic.value())
{
println!("Instantaneous FT: {:?}", instantaneous_ft);
}
}
#[derive(Resource)]
struct DiagnosticsRecorder {
start_time: Option<f64>,
data: Vec<(f64, f64, f64, f64, f64)>, // (time, avg_fps, instantaneous_fps, avg_frame_time, instantaneous_frame_time)
}
fn start_recording_system(time: Res<Time>, mut recorder: ResMut<DiagnosticsRecorder>) {
if recorder.start_time.is_none() {
recorder.start_time = Some(time.elapsed_secs_f64());
}
}
fn record_diagnostics_system(
time: Res<Time>,
diagnostics: Res<DiagnosticsStore>,
mut recorder: ResMut<DiagnosticsRecorder>,
mut z_index: ResMut<game::ZIndex>,
mut camera_moved: ResMut<CameraMoved>,
) {
if let Some(start_time) = recorder.start_time {
let elapsed = time.elapsed_secs_f64() - start_time;
camera_moved.0 = false;
// Set z_index to -3 at the start
if elapsed < 10.0 {
z_index.0 = -3.0;
camera_moved.0 = true;
}
// Increase z_index by +1 every 10 seconds
if elapsed >= 10.0 && elapsed % 10.0 < time.delta_secs_f64() {
z_index.0 += 1.0;
camera_moved.0 = true;
}
if elapsed >= 10.0 && elapsed <= 70.0 {
let avg_fps = diagnostics
.get(&FrameTimeDiagnosticsPlugin::FPS)
.and_then(|fps_diagnostic| fps_diagnostic.average())
.unwrap_or(0.0);
let instantaneous_fps = diagnostics
.get(&FrameTimeDiagnosticsPlugin::FPS)
.and_then(|fps_diagnostic| fps_diagnostic.value())
.unwrap_or(0.0);
let avg_frame_time = diagnostics
.get(&FrameTimeDiagnosticsPlugin::FRAME_TIME)
.and_then(|ft_diagnostic| ft_diagnostic.average())
.unwrap_or(0.0);
let instantaneous_frame_time = diagnostics
.get(&FrameTimeDiagnosticsPlugin::FRAME_TIME)
.and_then(|ft_diagnostic| ft_diagnostic.value())
.unwrap_or(0.0);
recorder.data.push((
elapsed,
avg_fps,
instantaneous_fps,
avg_frame_time,
instantaneous_frame_time,
));
} else if elapsed > 70.0 {
save_to_csv(&recorder.data);
std::process::exit(0);
}
}
}
fn save_to_csv(data: &[(f64, f64, f64, f64, f64)]) {
if let Ok(mut file) = File::create("diagnostics.csv") {
writeln!(
file,
"Time,Avg FPS,Instantaneous FPS,Avg Frame Time,Instantaneous Frame Time"
)
.unwrap();
for (time, avg_fps, instantaneous_fps, avg_frame_time, instantaneous_frame_time) in data {
writeln!(
file,
"{},{},{},{},{}",
time, avg_fps, instantaneous_fps, avg_frame_time, instantaneous_frame_time
)
.unwrap();
}
} else {
eprintln!("Failed to create diagnostics.csv");
}
}
impl Default for DiagnosticsRecorder {
fn default() -> Self {
DiagnosticsRecorder {
start_time: None,
data: Vec::new(),
}
}
}
+2 -2
View File
@@ -285,8 +285,8 @@ fn handle_chunk_loading(
fn setup_initial_chunks(mut event_writer: EventWriter<LoadChunkEvent>) {
println!("setup_initial_chunks");
for x in -6..=6 {
for y in -3..=3 {
for x in -7..=7 {
for y in -7..=7 {
event_writer.send(LoadChunkEvent {
chunk_position: IVec2::new(x, y),
});