-
-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added initial benchmarks, similar to bevy_xpbd
- Loading branch information
Showing
4 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "benches_common" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
bevy = { version = "0.14.0-rc.3", default-features = false } | ||
bevy_rapier3d = { path = "../bevy_rapier3d", default-features = false } | ||
criterion = "0.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use bevy::{ | ||
app::PluginsState, | ||
prelude::*, | ||
render::{ | ||
settings::{RenderCreation, WgpuSettings}, | ||
RenderPlugin, | ||
}, | ||
scene::ScenePlugin, | ||
time::TimeUpdateStrategy, | ||
}; | ||
use bevy_rapier3d::prelude::*; | ||
use criterion::{measurement::Measurement, BatchSize, Bencher}; | ||
|
||
pub fn bench_app<M: Measurement>( | ||
bencher: &mut Bencher<'_, M>, | ||
steps: u32, | ||
setup: impl Fn(&mut App), | ||
) { | ||
bencher.iter_batched_ref( | ||
move || { | ||
let mut app = App::new(); | ||
|
||
app.add_plugins(( | ||
WindowPlugin::default(), | ||
MinimalPlugins, | ||
AssetPlugin::default(), | ||
ScenePlugin, | ||
RenderPlugin { | ||
render_creation: RenderCreation::Automatic(WgpuSettings { | ||
backends: None, | ||
..Default::default() | ||
}), | ||
..Default::default() | ||
}, | ||
ImagePlugin::default(), | ||
HierarchyPlugin, | ||
TransformPlugin, | ||
RapierPhysicsPlugin::<()>::default(), | ||
)); | ||
|
||
// 60 physics | ||
app.insert_resource(TimeUpdateStrategy::ManualDuration( | ||
std::time::Duration::from_secs_f32(1f32 / 60f32), | ||
)); | ||
|
||
setup(&mut app); | ||
|
||
while app.plugins_state() != PluginsState::Ready { | ||
bevy::tasks::tick_global_task_pools_on_main_thread(); | ||
} | ||
|
||
app.finish(); | ||
app.cleanup(); | ||
app | ||
}, | ||
move |app| { | ||
for _ in 0..steps { | ||
app.update(); | ||
} | ||
}, | ||
BatchSize::PerIteration, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::time::Duration; | ||
|
||
use benches_common::bench_app; | ||
use bevy::prelude::*; | ||
use bevy_rapier3d::math::*; | ||
use bevy_rapier3d::prelude::*; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
|
||
fn setup_cubes(app: &mut App, size: u32) { | ||
app.add_systems(Startup, move |mut commands: Commands| { | ||
commands.spawn(( | ||
RigidBody::Fixed, | ||
Transform::from_translation(-2.0 * Vect::Z), | ||
Collider::cuboid(100.0, 1.0, 100.0), | ||
)); | ||
for x in 0..size { | ||
for z in 0..size { | ||
commands.spawn(( | ||
RigidBody::Dynamic, | ||
Transform::from_translation(Vec3::new(x as f32, 2.0, z as f32)), | ||
Collider::cuboid(1.0, 1.0, 1.0), | ||
)); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
c.bench_function("cubes 3x3, 30 steps", |b| { | ||
bench_app(b, 30, |app| setup_cubes(app, 3)) | ||
}); | ||
|
||
c.bench_function("cubes 5x5, 30 steps", |b| { | ||
bench_app(b, 30, |app| setup_cubes(app, 5)) | ||
}); | ||
|
||
c.bench_function("cubes 10x10, 30 steps", |b| { | ||
bench_app(b, 30, |app| setup_cubes(app, 10)) | ||
}); | ||
} | ||
|
||
criterion_group!( | ||
name = benches; | ||
config = Criterion::default().measurement_time(Duration::from_secs(20)); | ||
targets = criterion_benchmark | ||
); | ||
criterion_main!(benches); |