-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into contact-manifolds
- Loading branch information
Showing
6 changed files
with
132 additions
and
10 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_3d" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
bevy = { version = "0.11", default-features = false } | ||
bevy_xpbd_3d = { path = "../bevy_xpbd_3d", default-features = false } | ||
criterion = "0.4" |
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,40 @@ | ||
use bevy::prelude::*; | ||
use bevy_xpbd_3d::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(( | ||
MinimalPlugins, | ||
HierarchyPlugin, | ||
TransformPlugin, | ||
PhysicsPlugins::default(), | ||
)); | ||
|
||
app.insert_resource(PhysicsTimestep::FixedOnce(1.0 / 60.0)); | ||
|
||
setup(&mut app); | ||
|
||
while !app.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,48 @@ | ||
use std::time::Duration; | ||
|
||
use benches_common_3d::bench_app; | ||
use bevy::prelude::*; | ||
use bevy_xpbd_3d::math::*; | ||
use bevy_xpbd_3d::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::Static, | ||
Position(-2.0 * Vector::Z), | ||
Collider::cuboid(100.0, 1.0, 100.0), | ||
)); | ||
|
||
for x in 0..size { | ||
for z in 0..size { | ||
commands.spawn(( | ||
RigidBody::Dynamic, | ||
Position(Vector::new(x as Scalar, 2.0, z as Scalar)), | ||
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); |
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