diff --git a/benches/Cargo.toml b/benches/Cargo.toml index 6375af6d5e..17b98eaaaf 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -4,6 +4,8 @@ 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" @@ -30,62 +32,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" +path = "benches/bevy_ecs/main.rs" harness = false [[bench]] -name = "ray_mesh_intersection" -path = "benches/bevy_picking/ray_mesh_intersection.rs" +name = "math" +path = "benches/bevy_math/main.rs" harness = false [[bench]] -name = "reflect_function" -path = "benches/bevy_reflect/function.rs" +name = "picking" +path = "benches/bevy_picking/main.rs" harness = false [[bench]] -name = "reflect_list" -path = "benches/bevy_reflect/list.rs" +name = "reflect" +path = "benches/bevy_reflect/main.rs" harness = false [[bench]] -name = "reflect_map" -path = "benches/bevy_reflect/map.rs" +name = "render" +path = "benches/bevy_render/main.rs" harness = false [[bench]] -name = "reflect_struct" -path = "benches/bevy_reflect/struct.rs" -harness = false - -[[bench]] -name = "parse_reflect_path" -path = "benches/bevy_reflect/path.rs" -harness = false - -[[bench]] -name = "iter" -path = "benches/bevy_tasks/iter.rs" -harness = false - -[[bench]] -name = "bezier" -path = "benches/bevy_math/bezier.rs" -harness = false - -[[bench]] -name = "torus" -path = "benches/bevy_render/torus.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/change_detection.rs b/benches/benches/bevy_ecs/change_detection.rs index f0a3eaa614..3f9f1d4bc1 100644 --- a/benches/benches/bevy_ecs/change_detection.rs +++ b/benches/benches/bevy_ecs/change_detection.rs @@ -5,19 +5,18 @@ 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; criterion_group!( - benches, + change_detection_benches, all_added_detection, all_changed_detection, few_changed_detection, none_changed_detection, multiple_archetype_none_changed_detection ); -criterion_main!(benches); macro_rules! modify { ($components:ident;$($index:tt),*) => { diff --git a/benches/benches/bevy_ecs/empty_archetypes.rs b/benches/benches/bevy_ecs/empty_archetypes.rs index d6521303f6..254dde4614 100644 --- a/benches/benches/bevy_ecs/empty_archetypes.rs +++ b/benches/benches/bevy_ecs/empty_archetypes.rs @@ -1,9 +1,7 @@ use bevy_ecs::{component::Component, prelude::*, world::World}; -use bevy_tasks::{ComputeTaskPool, TaskPool}; -use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion}; +use criterion::{black_box, criterion_group, BenchmarkId, Criterion}; -criterion_group!(benches, empty_archetypes); -criterion_main!(benches); +criterion_group!(empty_archetypes_benches, empty_archetypes); #[derive(Component)] struct A(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,17 +67,18 @@ fn par_for_each( &A<12>, )>, ) { - query.par_for_each(&*task_pool, 64, |comp| { + query.par_iter().for_each(|comp| { black_box(comp); }); } +#[expect( + unused_variables, + reason = "`parallel` has no effect, it needs to be removed or parallel support needs to be re-added." +)] 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())); - } setup(&mut schedule); (world, schedule) } @@ -88,7 +86,7 @@ fn setup(parallel: bool, setup: impl FnOnce(&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 +156,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 +187,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 +218,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/benches.rs b/benches/benches/bevy_ecs/main.rs similarity index 79% rename from benches/benches/bevy_ecs/benches.rs rename to benches/benches/bevy_ecs/main.rs index 58300bda95..b60492b41f 100644 --- a/benches/benches/bevy_ecs/benches.rs +++ b/benches/benches/bevy_ecs/main.rs @@ -2,7 +2,9 @@ use criterion::criterion_main; +mod change_detection; mod components; +mod empty_archetypes; mod events; mod fragmentation; mod iteration; @@ -12,7 +14,9 @@ mod scheduling; mod world; criterion_main!( + change_detection::change_detection_benches, components::components_benches, + empty_archetypes::empty_archetypes_benches, events::event_benches, iteration::iterations_benches, fragmentation::fragmentation_benches, diff --git a/benches/benches/bevy_ecs/world/entity_hash.rs b/benches/benches/bevy_ecs/world/entity_hash.rs index 3bd148d90d..d4ba9b6598 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 a88f034776..652221c126 100644 --- a/benches/benches/bevy_ecs/world/mod.rs +++ b/benches/benches/bevy_ecs/world/mod.rs @@ -39,5 +39,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_math/bezier.rs b/benches/benches/bevy_math/bezier.rs index 4728d2b058..c367cb3029 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 0000000000..56f2904bcd --- /dev/null +++ b/benches/benches/bevy_math/main.rs @@ -0,0 +1,7 @@ +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 0000000000..c9177c0080 --- /dev/null +++ b/benches/benches/bevy_picking/main.rs @@ -0,0 +1,7 @@ +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 f451b79061..1d019d43ee 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 03673d3a9a..7489130418 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, 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 e5fffaa3cd..c02205e3f9 100644 --- a/benches/benches/bevy_reflect/list.rs +++ b/benches/benches/bevy_reflect/list.rs @@ -2,7 +2,7 @@ use core::{iter, time::Duration}; use bevy_reflect::{DynamicList, List}; use criterion::{ - black_box, criterion_group, criterion_main, measurement::Measurement, BatchSize, + black_box, criterion_group, measurement::Measurement, BatchSize, BenchmarkGroup, BenchmarkId, Criterion, Throughput, }; @@ -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 0000000000..3785652295 --- /dev/null +++ b/benches/benches/bevy_reflect/main.rs @@ -0,0 +1,15 @@ +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 ae38948813..8857cb9fac 100644 --- a/benches/benches/bevy_reflect/map.rs +++ b/benches/benches/bevy_reflect/map.rs @@ -3,7 +3,7 @@ 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, + black_box, criterion_group, measurement::Measurement, BatchSize, BenchmarkGroup, BenchmarkId, Criterion, Throughput, }; @@ -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); diff --git a/benches/benches/bevy_reflect/path.rs b/benches/benches/bevy_reflect/path.rs index f18885132a..576884191d 100644 --- a/benches/benches/bevy_reflect/path.rs +++ b/benches/benches/bevy_reflect/path.rs @@ -2,13 +2,12 @@ use core::{fmt::Write, str, time::Duration}; use bevy_reflect::ParsedPath; use criterion::{ - black_box, criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput, + 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); diff --git a/benches/benches/bevy_reflect/struct.rs b/benches/benches/bevy_reflect/struct.rs index 0a38088666..9b73a1d850 100644 --- a/benches/benches/bevy_reflect/struct.rs +++ b/benches/benches/bevy_reflect/struct.rs @@ -2,7 +2,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, + black_box, criterion_group, BatchSize, BenchmarkId, Criterion, Throughput, }; criterion_group!( @@ -16,7 +16,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); diff --git a/benches/benches/bevy_render/main.rs b/benches/benches/bevy_render/main.rs new file mode 100644 index 0000000000..e3987123eb --- /dev/null +++ b/benches/benches/bevy_render/main.rs @@ -0,0 +1,9 @@ +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 84f6b89077..409079f202 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; @@ -16,4 +16,3 @@ criterion_group!( benches, render_layers, ); -criterion_main!(benches); diff --git a/benches/benches/bevy_render/torus.rs b/benches/benches/bevy_render/torus.rs index 199cc7ce4c..a5ef753bc8 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 3d4410926c..4f8f75c8ed 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 0000000000..cfe74f5dca --- /dev/null +++ b/benches/benches/bevy_tasks/main.rs @@ -0,0 +1,5 @@ +use criterion::criterion_main; + +mod iter; + +criterion_main!(iter::benches);