refactor: organize benches to be consistent

This commit is contained in:
BD103 2024-12-04 11:20:11 -05:00
parent 1e7b89cdf5
commit 5d26f56eb9
21 changed files with 88 additions and 85 deletions

View file

@ -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

View file

@ -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),*) => {

View file

@ -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<const N: u16>(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<ComputeTaskPool>,
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));

View file

@ -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,

View file

@ -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 {

View file

@ -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,
);

View file

@ -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);

View file

@ -0,0 +1,7 @@
use criterion::criterion_main;
mod bezier;
criterion_main!(
bezier::benches,
);

View file

@ -0,0 +1,7 @@
use criterion::criterion_main;
mod ray_mesh_intersection;
criterion_main!(
ray_mesh_intersection::benches,
);

View file

@ -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);

View file

@ -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

View file

@ -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);

View file

@ -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,
);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -0,0 +1,9 @@
use criterion::criterion_main;
mod render_layers;
mod torus;
criterion_main!(
render_layers::benches,
torus::benches,
);

View file

@ -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);

View file

@ -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);

View file

@ -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<core::slice::Iter<'a, T>> 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);

View file

@ -0,0 +1,5 @@
use criterion::criterion_main;
mod iter;
criterion_main!(iter::benches);