-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
Problem
I've slowly been returning to bevy-bencher
, and am trying to migrate it to use Bevy's in-tree benchmarks instead of custom ones. One of the original issues I had with this approach is that it's difficult to see what a benchmark is testing from its name alone. For example:
layers_intersect
entity_hash
easing_1000
param/combinator_system/8_piped_systems
concrete_list_clone_dynamic
ray_mesh_intersection/1000_vertices
despawn_world_recursive/100_entities
overhead_par_iter/threads_4
run_condition/yes_using_resource
All of these names were pulled from our current benchmarks, and are the names that would be displayed in Bencher's UI. Can you guess what each benchmark tracks specifically? Probably not, unless you're deeply familiar with that specific subsystem.
Solution
Now look at the same list again, but with a few changes:
render::render_layers::intersect
ecs::world::entity_hash
math::bezier::easing_1000
ecs::param::combinator_system::8_piped_systems
reflect::list::concrete_clone_dynamic
picking::ray_mesh_intersection/1000_vertices
ecs::world::despawn_recursive/100_entities
tasks::overhead_par_iter/threads_4
ecs::scheduling::run_condition/yes_using_resource
This naming scheme includes the module path in the benchmark name, and removes any redundant words from the benchmark name. There are a few benefits to this approach:
- The name is far clearer on what is being tested.
- It's easy to locate the benchmark from the name alone.
- With the name
render::render_layers::intersect
, you know the benchmark is withinbevy_render/render_layers.rs
.
- With the name
- You can easily filter benchmarks to run by category.
- For instance, you can run
cargo bench -- ecs::world
to run allWorld
-related benchmarks.
- For instance, you can run
Automation
We can automate this naming a little bit using macros, specifically with module_path!()
. For a quick sketch, you may be able to do this:
// I may have messed up this syntax, but you get the idea :)
macro_rules! bench {
($name:lit) => {
concat!(module_path!(), $name)
}
}
// Crate: `bevy_math`
mod bezier {
fn easing(c: &mut Criterion) {
// Name is `bevy_math::bezier::easing`.
c.bench_function(bench!("easing"), |b| {
// ...
});
}
}