diff --git a/benches/Cargo.toml b/benches/Cargo.toml index 6375af6d5e198..4841570022b0b 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -4,12 +4,11 @@ edition = "2021" description = "Benchmarks that test Bevy's performance" publish = false license = "MIT OR Apache-2.0" +# Do not automatically discover benchmarks, we specify them manually instead. +autobenches = false [dev-dependencies] -glam = "0.29" -rand = "0.8" -rand_chacha = "0.3" -criterion = { version = "0.3", features = ["html_reports"] } +# Bevy crates bevy_app = { path = "../crates/bevy_app" } bevy_ecs = { path = "../crates/bevy_ecs", features = ["multi_threaded"] } bevy_hierarchy = { path = "../crates/bevy_hierarchy" } @@ -22,7 +21,14 @@ bevy_render = { path = "../crates/bevy_render" } bevy_tasks = { path = "../crates/bevy_tasks" } bevy_utils = { path = "../crates/bevy_utils" } -# make bevy_render compile on linux. x11 vs wayland does not matter here as the benches do not actually use a window +# Other crates +criterion = { version = "0.5.1", features = ["html_reports"] } +glam = "0.29" +rand = "0.8" +rand_chacha = "0.3" + +# Make `bevy_render` compile on Linux with x11 windowing. x11 vs. Wayland does not matter here +# because the benches do not actually open any windows. [target.'cfg(target_os = "linux")'.dev-dependencies] bevy_winit = { path = "../crates/bevy_winit", features = ["x11"] } @@ -30,62 +36,32 @@ bevy_winit = { path = "../crates/bevy_winit", features = ["x11"] } opt-level = 3 lto = true -[[bench]] -name = "change_detection" -path = "benches/bevy_ecs/change_detection.rs" -harness = false - [[bench]] name = "ecs" -path = "benches/bevy_ecs/benches.rs" -harness = false - -[[bench]] -name = "ray_mesh_intersection" -path = "benches/bevy_picking/ray_mesh_intersection.rs" -harness = false - -[[bench]] -name = "reflect_function" -path = "benches/bevy_reflect/function.rs" -harness = false - -[[bench]] -name = "reflect_list" -path = "benches/bevy_reflect/list.rs" -harness = false - -[[bench]] -name = "reflect_map" -path = "benches/bevy_reflect/map.rs" -harness = false - -[[bench]] -name = "reflect_struct" -path = "benches/bevy_reflect/struct.rs" +path = "benches/bevy_ecs/main.rs" harness = false [[bench]] -name = "parse_reflect_path" -path = "benches/bevy_reflect/path.rs" +name = "math" +path = "benches/bevy_math/main.rs" harness = false [[bench]] -name = "iter" -path = "benches/bevy_tasks/iter.rs" +name = "picking" +path = "benches/bevy_picking/main.rs" harness = false [[bench]] -name = "bezier" -path = "benches/bevy_math/bezier.rs" +name = "reflect" +path = "benches/bevy_reflect/main.rs" harness = false [[bench]] -name = "torus" -path = "benches/bevy_render/torus.rs" +name = "render" +path = "benches/bevy_render/main.rs" harness = false [[bench]] -name = "entity_hash" -path = "benches/bevy_ecs/world/entity_hash.rs" +name = "tasks" +path = "benches/bevy_tasks/main.rs" harness = false diff --git a/benches/benches/bevy_ecs/benches.rs b/benches/benches/bevy_ecs/benches.rs deleted file mode 100644 index 58300bda95b5c..0000000000000 --- a/benches/benches/bevy_ecs/benches.rs +++ /dev/null @@ -1,23 +0,0 @@ -#![expect(dead_code, reason = "Many fields are unused/unread as they are just for benchmarking purposes.")] - -use criterion::criterion_main; - -mod components; -mod events; -mod fragmentation; -mod iteration; -mod observers; -mod param; -mod scheduling; -mod world; - -criterion_main!( - components::components_benches, - events::event_benches, - iteration::iterations_benches, - fragmentation::fragmentation_benches, - observers::observer_benches, - scheduling::scheduling_benches, - world::world_benches, - param::param_benches, -); diff --git a/benches/benches/bevy_ecs/change_detection.rs b/benches/benches/bevy_ecs/change_detection.rs index f0a3eaa61466d..a07320cf1809b 100644 --- a/benches/benches/bevy_ecs/change_detection.rs +++ b/benches/benches/bevy_ecs/change_detection.rs @@ -5,7 +5,7 @@ use bevy_ecs::{ query::QueryFilter, world::World, }; -use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use criterion::{black_box, criterion_group, Criterion}; use rand::{prelude::SliceRandom, SeedableRng}; use rand_chacha::ChaCha8Rng; @@ -17,7 +17,6 @@ criterion_group!( none_changed_detection, multiple_archetype_none_changed_detection ); -criterion_main!(benches); macro_rules! modify { ($components:ident;$($index:tt),*) => { @@ -96,7 +95,7 @@ fn all_added_detection_generic(group: &mut BenchGroup, e }, |(ref mut world, ref mut query)| { let mut count = 0; - for entity in query.iter(&world) { + for entity in query.iter(world) { black_box(entity); count += 1; } @@ -144,7 +143,7 @@ fn all_changed_detection_generic + Default + }, |(ref mut world, ref mut query)| { let mut count = 0; - for entity in query.iter(&world) { + for entity in query.iter(world) { black_box(entity); count += 1; } @@ -196,7 +195,7 @@ fn few_changed_detection_generic + Default + (world, query) }, |(ref mut world, ref mut query)| { - for entity in query.iter(&world) { + for entity in query.iter(world) { black_box(entity); } }, @@ -238,7 +237,7 @@ fn none_changed_detection_generic + Default>( }, |(ref mut world, ref mut query)| { let mut count = 0; - for entity in query.iter(&world) { + for entity in query.iter(world) { black_box(entity); count += 1; } @@ -298,7 +297,9 @@ fn add_archetypes_entities + Default>( } } } -fn multiple_archetype_none_changed_detection_generic + Default + BenchModify>( +fn multiple_archetype_none_changed_detection_generic< + T: Component + Default + BenchModify, +>( group: &mut BenchGroup, archetype_count: u16, entity_count: u32, @@ -342,7 +343,7 @@ fn multiple_archetype_none_changed_detection_generic(f32); @@ -47,13 +45,12 @@ fn for_each( &A<12>, )>, ) { - query.for_each(|comp| { + query.iter().for_each(|comp| { black_box(comp); }); } fn par_for_each( - task_pool: Res, query: Query<( &A<0>, &A<1>, @@ -70,25 +67,29 @@ fn par_for_each( &A<12>, )>, ) { - query.par_for_each(&*task_pool, 64, |comp| { + query.par_iter().for_each(|comp| { black_box(comp); }); } fn setup(parallel: bool, setup: impl FnOnce(&mut Schedule)) -> (World, Schedule) { - let mut world = World::new(); + let world = World::new(); let mut schedule = Schedule::default(); - if parallel { - world.insert_resource(ComputeTaskPool(TaskPool::default())); - } + + schedule.set_executor_kind(match parallel { + true => ExecutorKind::MultiThreaded, + false => ExecutorKind::SingleThreaded, + }); + setup(&mut schedule); + (world, schedule) } /// create `count` entities with distinct archetypes fn add_archetypes(world: &mut World, count: u16) { for i in 0..count { - let mut e = world.spawn(); + let mut e = world.spawn_empty(); e.insert(A::<0>(1.0)); e.insert(A::<1>(1.0)); e.insert(A::<2>(1.0)); @@ -158,7 +159,7 @@ fn empty_archetypes(criterion: &mut Criterion) { }); add_archetypes(&mut world, archetype_count); world.clear_entities(); - let mut e = world.spawn(); + let mut e = world.spawn_empty(); e.insert(A::<0>(1.0)); e.insert(A::<1>(1.0)); e.insert(A::<2>(1.0)); @@ -189,7 +190,7 @@ fn empty_archetypes(criterion: &mut Criterion) { }); add_archetypes(&mut world, archetype_count); world.clear_entities(); - let mut e = world.spawn(); + let mut e = world.spawn_empty(); e.insert(A::<0>(1.0)); e.insert(A::<1>(1.0)); e.insert(A::<2>(1.0)); @@ -220,7 +221,7 @@ fn empty_archetypes(criterion: &mut Criterion) { }); add_archetypes(&mut world, archetype_count); world.clear_entities(); - let mut e = world.spawn(); + let mut e = world.spawn_empty(); e.insert(A::<0>(1.0)); e.insert(A::<1>(1.0)); e.insert(A::<2>(1.0)); diff --git a/benches/benches/bevy_ecs/events/mod.rs b/benches/benches/bevy_ecs/events/mod.rs index 5d20ef25cd018..4367c45c3e28d 100644 --- a/benches/benches/bevy_ecs/events/mod.rs +++ b/benches/benches/bevy_ecs/events/mod.rs @@ -1,9 +1,9 @@ -use criterion::*; - mod iter; mod send; -criterion_group!(event_benches, send, iter); +use criterion::{criterion_group, Criterion}; + +criterion_group!(benches, send, iter); fn send(c: &mut Criterion) { let mut group = c.benchmark_group("events_send"); diff --git a/benches/benches/bevy_ecs/fragmentation/mod.rs b/benches/benches/bevy_ecs/fragmentation.rs similarity index 98% rename from benches/benches/bevy_ecs/fragmentation/mod.rs rename to benches/benches/bevy_ecs/fragmentation.rs index ae44aae4a48c5..97864990a37e5 100644 --- a/benches/benches/bevy_ecs/fragmentation/mod.rs +++ b/benches/benches/bevy_ecs/fragmentation.rs @@ -1,10 +1,10 @@ use bevy_ecs::prelude::*; use bevy_ecs::system::SystemState; +use core::hint::black_box; use criterion::*; use glam::*; -use core::hint::black_box; -criterion_group!(fragmentation_benches, iter_frag_empty); +criterion_group!(benches, iter_frag_empty); #[derive(Component, Default)] struct Table(usize); diff --git a/benches/benches/bevy_ecs/iteration/mod.rs b/benches/benches/bevy_ecs/iteration/mod.rs index 62d8b166040dc..0fa7aced2894a 100644 --- a/benches/benches/bevy_ecs/iteration/mod.rs +++ b/benches/benches/bevy_ecs/iteration/mod.rs @@ -1,5 +1,3 @@ -use criterion::*; - mod heavy_compute; mod iter_frag; mod iter_frag_foreach; @@ -22,10 +20,11 @@ mod iter_simple_wide_sparse_set; mod par_iter_simple; mod par_iter_simple_foreach_hybrid; +use criterion::{criterion_group, Criterion}; use heavy_compute::*; criterion_group!( - iterations_benches, + benches, iter_frag, iter_frag_sparse, iter_simple, @@ -136,7 +135,7 @@ fn par_iter_simple(c: &mut Criterion) { b.iter(move || bench.run()); }); } - group.bench_function(format!("hybrid"), |b| { + group.bench_function("hybrid".to_string(), |b| { let mut bench = par_iter_simple_foreach_hybrid::Benchmark::new(); b.iter(move || bench.run()); }); diff --git a/benches/benches/bevy_ecs/main.rs b/benches/benches/bevy_ecs/main.rs new file mode 100644 index 0000000000000..83f0cde0286d6 --- /dev/null +++ b/benches/benches/bevy_ecs/main.rs @@ -0,0 +1,31 @@ +#![expect( + dead_code, + reason = "Many fields are unused/unread as they are just for benchmarking purposes." +)] +#![expect(clippy::type_complexity)] + +use criterion::criterion_main; + +mod change_detection; +mod components; +mod empty_archetypes; +mod events; +mod fragmentation; +mod iteration; +mod observers; +mod param; +mod scheduling; +mod world; + +criterion_main!( + change_detection::benches, + components::benches, + empty_archetypes::benches, + events::benches, + iteration::benches, + fragmentation::benches, + observers::benches, + scheduling::benches, + world::benches, + param::benches, +); diff --git a/benches/benches/bevy_ecs/observers/mod.rs b/benches/benches/bevy_ecs/observers/mod.rs index 0b8c3f24869ce..16008def7e461 100644 --- a/benches/benches/bevy_ecs/observers/mod.rs +++ b/benches/benches/bevy_ecs/observers/mod.rs @@ -1,8 +1,8 @@ -use criterion::criterion_group; - mod propagation; mod simple; + +use criterion::criterion_group; use propagation::*; use simple::*; -criterion_group!(observer_benches, event_propagation, observe_simple); +criterion_group!(benches, event_propagation, observe_simple); diff --git a/benches/benches/bevy_ecs/observers/propagation.rs b/benches/benches/bevy_ecs/observers/propagation.rs index acd07aac566e7..5de85bc3269b2 100644 --- a/benches/benches/bevy_ecs/observers/propagation.rs +++ b/benches/benches/bevy_ecs/observers/propagation.rs @@ -71,7 +71,7 @@ impl Event for TestEvent { const AUTO_PROPAGATE: bool = true; } -fn send_events(world: &mut World, leaves: &Vec) { +fn send_events(world: &mut World, leaves: &[Entity]) { let target = leaves.iter().choose(&mut rand::thread_rng()).unwrap(); (0..N_EVENTS).for_each(|_| { @@ -100,9 +100,9 @@ fn spawn_listener_hierarchy(world: &mut World) -> (Vec, Vec, Vec } fn add_listeners_to_hierarchy( - roots: &Vec, - leaves: &Vec, - nodes: &Vec, + roots: &[Entity], + leaves: &[Entity], + nodes: &[Entity], world: &mut World, ) { for e in roots.iter() { diff --git a/benches/benches/bevy_ecs/param/mod.rs b/benches/benches/bevy_ecs/param/mod.rs index 20955fc29e02b..6cc6132f66787 100644 --- a/benches/benches/bevy_ecs/param/mod.rs +++ b/benches/benches/bevy_ecs/param/mod.rs @@ -1,11 +1,10 @@ -use criterion::criterion_group; - mod combinator_system; mod dyn_param; mod param_set; use combinator_system::*; +use criterion::criterion_group; use dyn_param::*; use param_set::*; -criterion_group!(param_benches, combinator_system, dyn_param, param_set); +criterion_group!(benches, combinator_system, dyn_param, param_set); diff --git a/benches/benches/bevy_ecs/scheduling/mod.rs b/benches/benches/bevy_ecs/scheduling/mod.rs index 60d1620a89f5c..310662e629cad 100644 --- a/benches/benches/bevy_ecs/scheduling/mod.rs +++ b/benches/benches/bevy_ecs/scheduling/mod.rs @@ -1,15 +1,14 @@ -use criterion::criterion_group; - mod run_condition; mod running_systems; mod schedule; +use criterion::criterion_group; use run_condition::*; use running_systems::*; use schedule::*; criterion_group!( - scheduling_benches, + benches, run_condition_yes, run_condition_no, run_condition_yes_with_query, diff --git a/benches/benches/bevy_ecs/scheduling/run_condition.rs b/benches/benches/bevy_ecs/scheduling/run_condition.rs index c88d89b1fe8f8..0d6e4107c6245 100644 --- a/benches/benches/bevy_ecs/scheduling/run_condition.rs +++ b/benches/benches/bevy_ecs/scheduling/run_condition.rs @@ -25,7 +25,7 @@ pub fn run_condition_yes(criterion: &mut Criterion) { } // run once to initialize systems schedule.run(&mut world); - group.bench_function(&format!("{:03}_systems", 5 * amount + 1), |bencher| { + group.bench_function(format!("{:03}_systems", 5 * amount + 1), |bencher| { bencher.iter(|| { schedule.run(&mut world); }); @@ -48,7 +48,7 @@ pub fn run_condition_no(criterion: &mut Criterion) { } // run once to initialize systems schedule.run(&mut world); - group.bench_function(&format!("{:03}_systems", 5 * amount + 1), |bencher| { + group.bench_function(format!("{:03}_systems", 5 * amount + 1), |bencher| { bencher.iter(|| { schedule.run(&mut world); }); @@ -80,7 +80,7 @@ pub fn run_condition_yes_with_query(criterion: &mut Criterion) { } // run once to initialize systems schedule.run(&mut world); - group.bench_function(&format!("{:03}_systems", 5 * amount + 1), |bencher| { + group.bench_function(format!("{:03}_systems", 5 * amount + 1), |bencher| { bencher.iter(|| { schedule.run(&mut world); }); @@ -109,7 +109,7 @@ pub fn run_condition_yes_with_resource(criterion: &mut Criterion) { } // run once to initialize systems schedule.run(&mut world); - group.bench_function(&format!("{:03}_systems", 5 * amount + 1), |bencher| { + group.bench_function(format!("{:03}_systems", 5 * amount + 1), |bencher| { bencher.iter(|| { schedule.run(&mut world); }); diff --git a/benches/benches/bevy_ecs/scheduling/running_systems.rs b/benches/benches/bevy_ecs/scheduling/running_systems.rs index d2ea51307f87f..4a1455388549f 100644 --- a/benches/benches/bevy_ecs/scheduling/running_systems.rs +++ b/benches/benches/bevy_ecs/scheduling/running_systems.rs @@ -26,7 +26,7 @@ pub fn empty_systems(criterion: &mut Criterion) { schedule.add_systems(empty); } schedule.run(&mut world); - group.bench_function(&format!("{:03}_systems", amount), |bencher| { + group.bench_function(format!("{:03}_systems", amount), |bencher| { bencher.iter(|| { schedule.run(&mut world); }); @@ -38,7 +38,7 @@ pub fn empty_systems(criterion: &mut Criterion) { schedule.add_systems((empty, empty, empty, empty, empty)); } schedule.run(&mut world); - group.bench_function(&format!("{:03}_systems", 5 * amount), |bencher| { + group.bench_function(format!("{:03}_systems", 5 * amount), |bencher| { bencher.iter(|| { schedule.run(&mut world); }); @@ -80,7 +80,7 @@ pub fn busy_systems(criterion: &mut Criterion) { } schedule.run(&mut world); group.bench_function( - &format!( + format!( "{:02}x_entities_{:02}_systems", entity_bunches, 3 * system_amount + 3 @@ -131,7 +131,7 @@ pub fn contrived(criterion: &mut Criterion) { } schedule.run(&mut world); group.bench_function( - &format!( + format!( "{:02}x_entities_{:02}_systems", entity_bunches, 3 * system_amount + 3 diff --git a/benches/benches/bevy_ecs/scheduling/schedule.rs b/benches/benches/bevy_ecs/scheduling/schedule.rs index 4571899a9b7b5..1a428b5eb85fe 100644 --- a/benches/benches/bevy_ecs/scheduling/schedule.rs +++ b/benches/benches/bevy_ecs/scheduling/schedule.rs @@ -74,7 +74,7 @@ pub fn build_schedule(criterion: &mut Criterion) { // Method: generate a set of `graph_size` systems which have a One True Ordering. // Add system to the schedule with full constraints. Hopefully this should be maximally // difficult for bevy to figure out. - let labels: Vec<_> = (0..1000).map(|i| NumSet(i)).collect(); + let labels: Vec<_> = (0..1000).map(NumSet).collect(); // Benchmark graphs of different sizes. for graph_size in [100, 500, 1000] { diff --git a/benches/benches/bevy_ecs/world/entity_hash.rs b/benches/benches/bevy_ecs/world/entity_hash.rs index 3bd148d90da63..d4ba9b659820f 100644 --- a/benches/benches/bevy_ecs/world/entity_hash.rs +++ b/benches/benches/bevy_ecs/world/entity_hash.rs @@ -1,11 +1,8 @@ use bevy_ecs::entity::{Entity, EntityHashSet}; -use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; +use criterion::{BenchmarkId, Criterion, Throughput}; use rand::{Rng, SeedableRng}; use rand_chacha::ChaCha8Rng; -criterion_group!(benches, entity_set_build_and_lookup,); -criterion_main!(benches); - const SIZES: [usize; 5] = [100, 316, 1000, 3162, 10000]; fn make_entity(rng: &mut impl Rng, size: usize) -> Entity { diff --git a/benches/benches/bevy_ecs/world/mod.rs b/benches/benches/bevy_ecs/world/mod.rs index a88f034776852..e35dc999c2eb8 100644 --- a/benches/benches/bevy_ecs/world/mod.rs +++ b/benches/benches/bevy_ecs/world/mod.rs @@ -1,25 +1,20 @@ -use criterion::criterion_group; - mod commands; -use commands::*; - mod despawn; -use despawn::*; - mod despawn_recursive; -use despawn_recursive::*; - +mod entity_hash; mod spawn; -use spawn::*; - mod world_get; -use world_get::*; -mod entity_hash; +use commands::*; +use criterion::criterion_group; +use despawn::*; +use despawn_recursive::*; use entity_hash::*; +use spawn::*; +use world_get::*; criterion_group!( - world_benches, + benches, empty_commands, spawn_commands, insert_commands, @@ -39,5 +34,5 @@ criterion_group!( query_get_many::<2>, query_get_many::<5>, query_get_many::<10>, - entity_set_build_and_lookup + entity_set_build_and_lookup, ); diff --git a/benches/benches/bevy_ecs/world/world_get.rs b/benches/benches/bevy_ecs/world/world_get.rs index 4c235cd1b46e3..190402fbadb27 100644 --- a/benches/benches/bevy_ecs/world/world_get.rs +++ b/benches/benches/bevy_ecs/world/world_get.rs @@ -306,7 +306,7 @@ pub fn query_get(criterion: &mut Criterion) { } pub fn query_get_many(criterion: &mut Criterion) { - let mut group = criterion.benchmark_group(&format!("query_get_many_{N}")); + let mut group = criterion.benchmark_group(format!("query_get_many_{N}")); group.warm_up_time(core::time::Duration::from_millis(500)); group.measurement_time(core::time::Duration::from_secs(2 * N as u64)); diff --git a/benches/benches/bevy_math/bezier.rs b/benches/benches/bevy_math/bezier.rs index 4728d2b058ef0..c367cb30298dd 100644 --- a/benches/benches/bevy_math/bezier.rs +++ b/benches/benches/bevy_math/bezier.rs @@ -1,4 +1,4 @@ -use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use criterion::{black_box, criterion_group, Criterion}; use bevy_math::prelude::*; @@ -92,4 +92,3 @@ criterion_group!( build_pos_cubic, build_accel_cubic, ); -criterion_main!(benches); diff --git a/benches/benches/bevy_math/main.rs b/benches/benches/bevy_math/main.rs new file mode 100644 index 0000000000000..7b84b6d60f41b --- /dev/null +++ b/benches/benches/bevy_math/main.rs @@ -0,0 +1,5 @@ +use criterion::criterion_main; + +mod bezier; + +criterion_main!(bezier::benches); diff --git a/benches/benches/bevy_picking/main.rs b/benches/benches/bevy_picking/main.rs new file mode 100644 index 0000000000000..d3939d82ee6fc --- /dev/null +++ b/benches/benches/bevy_picking/main.rs @@ -0,0 +1,5 @@ +use criterion::criterion_main; + +mod ray_mesh_intersection; + +criterion_main!(ray_mesh_intersection::benches); diff --git a/benches/benches/bevy_picking/ray_mesh_intersection.rs b/benches/benches/bevy_picking/ray_mesh_intersection.rs index f451b790612c3..1d019d43ee37f 100644 --- a/benches/benches/bevy_picking/ray_mesh_intersection.rs +++ b/benches/benches/bevy_picking/ray_mesh_intersection.rs @@ -1,6 +1,6 @@ use bevy_math::{Dir3, Mat4, Ray3d, Vec3}; use bevy_picking::mesh_picking::ray_cast; -use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use criterion::{black_box, criterion_group, Criterion}; fn ptoxznorm(p: u32, size: u32) -> (f32, f32) { let ij = (p / (size), p % (size)); @@ -117,4 +117,3 @@ criterion_group!( ray_mesh_intersection_no_cull, ray_mesh_intersection_no_intersection ); -criterion_main!(benches); diff --git a/benches/benches/bevy_reflect/function.rs b/benches/benches/bevy_reflect/function.rs index b82466884f7d7..f40b9149eec64 100644 --- a/benches/benches/bevy_reflect/function.rs +++ b/benches/benches/bevy_reflect/function.rs @@ -1,8 +1,7 @@ use bevy_reflect::func::{ArgList, IntoFunction, IntoFunctionMut, TypedFunction}; -use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; +use criterion::{criterion_group, BatchSize, Criterion}; criterion_group!(benches, typed, into, call, overload, clone); -criterion_main!(benches); fn add(a: i32, b: i32) -> i32 { a + b diff --git a/benches/benches/bevy_reflect/list.rs b/benches/benches/bevy_reflect/list.rs index e5fffaa3cddf0..d9c92dd03ef06 100644 --- a/benches/benches/bevy_reflect/list.rs +++ b/benches/benches/bevy_reflect/list.rs @@ -2,8 +2,8 @@ use core::{iter, time::Duration}; use bevy_reflect::{DynamicList, List}; use criterion::{ - black_box, criterion_group, criterion_main, measurement::Measurement, BatchSize, - BenchmarkGroup, BenchmarkId, Criterion, Throughput, + black_box, criterion_group, measurement::Measurement, BatchSize, BenchmarkGroup, BenchmarkId, + Criterion, Throughput, }; criterion_group!( @@ -13,7 +13,6 @@ criterion_group!( dynamic_list_apply, dynamic_list_push ); -criterion_main!(benches); const WARM_UP_TIME: Duration = Duration::from_millis(500); const MEASUREMENT_TIME: Duration = Duration::from_secs(4); diff --git a/benches/benches/bevy_reflect/main.rs b/benches/benches/bevy_reflect/main.rs new file mode 100644 index 0000000000000..d347baccd0fa3 --- /dev/null +++ b/benches/benches/bevy_reflect/main.rs @@ -0,0 +1,17 @@ +#![expect(clippy::type_complexity)] + +use criterion::criterion_main; + +mod function; +mod list; +mod map; +mod path; +mod r#struct; + +criterion_main!( + function::benches, + list::benches, + map::benches, + path::benches, + r#struct::benches, +); diff --git a/benches/benches/bevy_reflect/map.rs b/benches/benches/bevy_reflect/map.rs index ae3894881358e..054dcf9570da0 100644 --- a/benches/benches/bevy_reflect/map.rs +++ b/benches/benches/bevy_reflect/map.rs @@ -3,8 +3,8 @@ use core::{fmt::Write, iter, time::Duration}; use bevy_reflect::{DynamicMap, Map}; use bevy_utils::HashMap; use criterion::{ - black_box, criterion_group, criterion_main, measurement::Measurement, BatchSize, - BenchmarkGroup, BenchmarkId, Criterion, Throughput, + black_box, criterion_group, measurement::Measurement, BatchSize, BenchmarkGroup, BenchmarkId, + Criterion, Throughput, }; criterion_group!( @@ -14,7 +14,6 @@ criterion_group!( dynamic_map_get, dynamic_map_insert ); -criterion_main!(benches); const WARM_UP_TIME: Duration = Duration::from_millis(500); const MEASUREMENT_TIME: Duration = Duration::from_secs(4); @@ -266,7 +265,7 @@ fn dynamic_map_insert(criterion: &mut Criterion) { |mut map| { for i in 0..size as u64 { let key = black_box(i); - black_box(map.insert(key, i)); + map.insert(key, black_box(i)); } }, BatchSize::SmallInput, diff --git a/benches/benches/bevy_reflect/path.rs b/benches/benches/bevy_reflect/path.rs index f18885132ac3f..2cca245239e89 100644 --- a/benches/benches/bevy_reflect/path.rs +++ b/benches/benches/bevy_reflect/path.rs @@ -1,14 +1,11 @@ use core::{fmt::Write, str, time::Duration}; use bevy_reflect::ParsedPath; -use criterion::{ - black_box, criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput, -}; +use criterion::{black_box, criterion_group, BatchSize, BenchmarkId, Criterion, Throughput}; use rand::{distributions::Uniform, Rng, SeedableRng}; use rand_chacha::ChaCha8Rng; criterion_group!(benches, parse_reflect_path); -criterion_main!(benches); const WARM_UP_TIME: Duration = Duration::from_millis(500); const MEASUREMENT_TIME: Duration = Duration::from_secs(2); @@ -20,7 +17,7 @@ fn deterministic_rand() -> ChaCha8Rng { ChaCha8Rng::seed_from_u64(42) } fn random_ident(rng: &mut ChaCha8Rng, f: &mut dyn Write) { - let between = Uniform::try_from(b'a'..=b'z').unwrap(); + let between = Uniform::from(b'a'..=b'z'); let ident_size = rng.gen_range(1..128); let ident: Vec = rng.sample_iter(between).take(ident_size).collect(); let ident = str::from_utf8(&ident).unwrap(); @@ -82,9 +79,9 @@ fn parse_reflect_path(criterion: &mut Criterion) { BenchmarkId::new("parse_reflect_path", size), &size, |bencher, &size| { - let mut mk_paths = mk_paths(size); + let mk_paths = mk_paths(size); bencher.iter_batched( - || mk_paths(), + mk_paths, |path| assert!(ParsedPath::parse(black_box(&path)).is_ok()), BatchSize::SmallInput, ); diff --git a/benches/benches/bevy_reflect/struct.rs b/benches/benches/bevy_reflect/struct.rs index 0a38088666f84..dfd324e7053e6 100644 --- a/benches/benches/bevy_reflect/struct.rs +++ b/benches/benches/bevy_reflect/struct.rs @@ -1,9 +1,7 @@ use core::time::Duration; use bevy_reflect::{DynamicStruct, GetField, PartialReflect, Reflect, Struct}; -use criterion::{ - black_box, criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput, -}; +use criterion::{black_box, criterion_group, BatchSize, BenchmarkId, Criterion, Throughput}; criterion_group!( benches, @@ -16,7 +14,6 @@ criterion_group!( dynamic_struct_get_field, dynamic_struct_insert, ); -criterion_main!(benches); const WARM_UP_TIME: Duration = Duration::from_millis(500); const MEASUREMENT_TIME: Duration = Duration::from_secs(4); @@ -316,7 +313,7 @@ fn dynamic_struct_insert(criterion: &mut Criterion) { bencher.iter_batched( || s.clone_dynamic(), |mut s| { - black_box(s.insert(black_box(&field), ())); + s.insert(black_box(&field), ()); }, BatchSize::SmallInput, ); diff --git a/benches/benches/bevy_render/main.rs b/benches/benches/bevy_render/main.rs new file mode 100644 index 0000000000000..7a369bc905705 --- /dev/null +++ b/benches/benches/bevy_render/main.rs @@ -0,0 +1,6 @@ +use criterion::criterion_main; + +mod render_layers; +mod torus; + +criterion_main!(render_layers::benches, torus::benches); diff --git a/benches/benches/bevy_render/render_layers.rs b/benches/benches/bevy_render/render_layers.rs index 84f6b8907754c..42dd5356b55ed 100644 --- a/benches/benches/bevy_render/render_layers.rs +++ b/benches/benches/bevy_render/render_layers.rs @@ -1,4 +1,4 @@ -use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use criterion::{black_box, criterion_group, Criterion}; use bevy_render::view::RenderLayers; @@ -6,14 +6,8 @@ fn render_layers(c: &mut Criterion) { c.bench_function("layers_intersect", |b| { let layer_a = RenderLayers::layer(1).with(2); let layer_b = RenderLayers::layer(1); - b.iter(|| { - black_box(layer_a.intersects(&layer_b)) - }); + b.iter(|| black_box(layer_a.intersects(&layer_b))); }); } -criterion_group!( - benches, - render_layers, -); -criterion_main!(benches); +criterion_group!(benches, render_layers); diff --git a/benches/benches/bevy_render/torus.rs b/benches/benches/bevy_render/torus.rs index 199cc7ce4c5ef..a5ef753bc8ccb 100644 --- a/benches/benches/bevy_render/torus.rs +++ b/benches/benches/bevy_render/torus.rs @@ -1,4 +1,4 @@ -use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use criterion::{black_box, criterion_group, Criterion}; use bevy_render::mesh::TorusMeshBuilder; @@ -8,5 +8,4 @@ fn torus(c: &mut Criterion) { }); } -criterion_group!(benches, torus,); -criterion_main!(benches); +criterion_group!(benches, torus); diff --git a/benches/benches/bevy_tasks/iter.rs b/benches/benches/bevy_tasks/iter.rs index 3d4410926cf11..4f8f75c8ed0e8 100644 --- a/benches/benches/bevy_tasks/iter.rs +++ b/benches/benches/bevy_tasks/iter.rs @@ -1,5 +1,5 @@ use bevy_tasks::{ParallelIterator, TaskPoolBuilder}; -use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion}; +use criterion::{black_box, criterion_group, BenchmarkId, Criterion}; struct ParChunks<'a, T>(core::slice::Chunks<'a, T>); impl<'a, T> ParallelIterator> for ParChunks<'a, T> @@ -141,4 +141,3 @@ fn bench_many_maps(c: &mut Criterion) { } criterion_group!(benches, bench_overhead, bench_for_each, bench_many_maps); -criterion_main!(benches); diff --git a/benches/benches/bevy_tasks/main.rs b/benches/benches/bevy_tasks/main.rs new file mode 100644 index 0000000000000..cfe74f5dca3de --- /dev/null +++ b/benches/benches/bevy_tasks/main.rs @@ -0,0 +1,5 @@ +use criterion::criterion_main; + +mod iter; + +criterion_main!(iter::benches);