Skip to content

Commit

Permalink
Parry benchmarks compilation (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrixyz authored Sep 16, 2024
1 parent 9f0270e commit 81229a5
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 51 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/parry-ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: parry CI build

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

env:
CARGO_TERM_COLOR: always
Expand Down Expand Up @@ -74,6 +74,16 @@ jobs:
- name: install stable Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
toolchain: stable
- name: cargo doc
run: cargo doc --workspace --features bytemuck-serialize,serde-serialize,rkyv-serialize,parallel --no-deps --document-private-items
check-benchmarks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install nightly Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
- name: check benchmarks
run: cargo +nightly check --benches
2 changes: 2 additions & 0 deletions crates/parry3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ oorandom = "11"
ptree = "0.4.0"
rand = { version = "0.8" }
macroquad = "0.4.12"
nalgebra = { version = "0.33", default-features = false, features = ["rand"] }
rand_isaac = "0.3"

[package.metadata.docs.rs]
rustdoc-args = ["-Zunstable-options", "--generate-link-to-definition"]
Expand Down
6 changes: 3 additions & 3 deletions crates/parry3d/benches/bounding_volume/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use na::Isometry3;
use parry3d::bounding_volume::BoundingVolume;
use parry3d::bounding_volume::{Aabb, BoundingSphere};
use parry3d::shape::{
Ball, Capsule, Cone, ConvexHull, Cuboid, Cylinder, Segment, TriMesh, Triangle,
Ball, Capsule, Cone, ConvexPolyhedron, Cuboid, Cylinder, Segment, TriMesh, Triangle,
};
use rand::SeedableRng;
use rand_isaac::IsaacRng;
Expand Down Expand Up @@ -135,13 +135,13 @@ bench_method!(
bench_method!(
bench_convex_aabb,
aabb: Aabb,
c: ConvexHull,
c: ConvexPolyhedron,
m: Isometry3<f32>
);
bench_method!(
bench_convex_bounding_sphere,
bounding_sphere: BoundingSphere,
c: ConvexHull,
c: ConvexPolyhedron,
m: Isometry3<f32>
);

Expand Down
23 changes: 13 additions & 10 deletions crates/parry3d/benches/common/default_gen.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use na::{
self, Isometry2, Isometry3, Matrix2, Matrix3, Matrix4, Point2, Point3, Point4, RealField,
Vector2, Vector3, Vector4,
self, Isometry2, Isometry3, Matrix2, Matrix3, Matrix4, Point2, Point3, Point4, Vector2,
Vector3, Vector4,
};
use parry3d::bounding_volume::{Aabb, BoundingSphere};
use parry3d::math::{Point, Real, Vector};
use parry3d::query::Ray;
use parry3d::shape::{Ball, Capsule, Cone, ConvexHull, Cuboid, Cylinder, Segment, Triangle};
use parry3d::shape::{Ball, Capsule, Cone, ConvexPolyhedron, Cuboid, Cylinder, Segment, Triangle};
use rand::distributions::{Distribution, Standard};
use rand::Rng;

Expand Down Expand Up @@ -76,7 +76,11 @@ where
Standard: Distribution<Real>,
{
fn generate<R: Rng>(rng: &mut R) -> Capsule {
Capsule::new(rng.gen::<Real>().abs(), rng.gen::<Real>().abs())
Capsule::new(
rng.gen::<Point<Real>>(),
rng.gen::<Point<Real>>(),
rng.gen::<Real>().abs(),
)
}
}

Expand Down Expand Up @@ -116,16 +120,15 @@ where
}
}

impl DefaultGen for ConvexHull
impl DefaultGen for ConvexPolyhedron
where
Standard: Distribution<Point<Real>>,
Standard: Distribution<Real>,
{
fn generate<R: Rng>(rng: &mut R) -> ConvexHull {
fn generate<R: Rng>(rng: &mut R) -> ConvexPolyhedron {
// It is recommended to have at most 100 points.
// Otherwise, a smarter structure like the DK hierarchy would be needed.
// let pts: Vec<_> = (0..100).map(|_| rng.gen()).collect();
// ConvexHull::try_from_points(&pts).unwrap()
unimplemented!()
let pts: Vec<_> = (0..100).map(|_| rng.gen()).collect();
ConvexPolyhedron::from_convex_hull(&pts).unwrap()
}
}

Expand Down
9 changes: 3 additions & 6 deletions crates/parry3d/benches/common/generators.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use na::{Point2, Point3};
use na::Point3;
use parry3d::shape::TriMesh;
use rand::Rng;

pub fn generate_trimesh_around_origin<R: Rng>(rng: &mut R) -> TriMesh {
let pts = (0..3000).map(|_| rng.gen::<Point3<f32>>() * 3.0).collect();
let uvs = (0..3000).map(|_| rng.gen::<Point2<f32>>() * 3.0).collect();
let indices = (0..1000)
.map(|i| Point3::new(i * 3, i * 3 + 1, i * 3 + 2))
.collect();
let indices = (0..1000).map(|i| [i * 3, i * 3 + 1, i * 3 + 2]).collect();

TriMesh::new(pts, indices, Some(uvs)).unwrap()
TriMesh::new(pts, indices).unwrap()
}
2 changes: 1 addition & 1 deletion crates/parry3d/benches/common/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ macro_rules! bench_method_gen (

unsafe {
let val: $tres = test::black_box($arg.get_unchecked(i).$method($(unref($args.get_unchecked(i)),)*));
drop(val);
let _ = val;
}
})
}
Expand Down
15 changes: 10 additions & 5 deletions crates/parry3d/benches/query/contacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,49 @@ mod macros;
bench_free_fn!(
bench_ball_against_ball,
query::contact,
pos12: Isometry3<f32>,
pos1: Isometry3<f32>,
b1: Ball,
pos2: Isometry3<f32>,
b2: Ball,
prediction: f32
);

bench_free_fn!(
bench_cuboid_against_cuboid,
query::contact,
pos12: Isometry3<f32>,
pos1: Isometry3<f32>,
b1: Cuboid,
pos2: Isometry3<f32>,
b2: Cuboid,
prediction: f32
);

bench_free_fn!(
bench_capsule_against_capsule,
query::contact,
pos12: Isometry3<f32>,
pos1: Isometry3<f32>,
b1: Capsule,
pos2: Isometry3<f32>,
b2: Capsule,
prediction: f32
);

bench_free_fn!(
bench_cone_against_cone,
query::contact,
pos12: Isometry3<f32>,
pos1: Isometry3<f32>,
b1: Cone,
pos2: Isometry3<f32>,
b2: Cone,
prediction: f32
);

bench_free_fn!(
bench_cylinder_against_cylinder,
query::contact,
pos12: Isometry3<f32>,
pos1: Isometry3<f32>,
b1: Cylinder,
pos2: Isometry3<f32>,
b2: Cylinder,
prediction: f32
);
40 changes: 20 additions & 20 deletions crates/parry3d/benches/query/ray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use na::Isometry3;
use parry3d::bounding_volume::{Aabb, BoundingSphere};
use parry3d::query::{Ray, RayCast};
use parry3d::shape::{
Ball, Capsule, Cone, ConvexHull, Cuboid, Cylinder, Segment, TriMesh, Triangle,
Ball, Capsule, Cone, ConvexPolyhedron, Cuboid, Cylinder, Segment, TriMesh, Triangle,
};
use rand::SeedableRng;
use rand_isaac::IsaacRng;
Expand Down Expand Up @@ -85,8 +85,8 @@ bench_method!(
);

bench_method!(
bench_ray_against_ball_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_ball_with_normal,
cast_ray_and_get_normal,
b: Ball,
pos: Isometry3<f32>,
ray: Ray,
Expand All @@ -95,8 +95,8 @@ bench_method!(
);

bench_method!(
bench_ray_against_cuboid_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_cuboid_with_normal,
cast_ray_and_get_normal,
c: Cuboid,
pos: Isometry3<f32>,
ray: Ray,
Expand All @@ -105,8 +105,8 @@ bench_method!(
);

bench_method!(
bench_ray_against_capsule_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_capsule_with_normal,
cast_ray_and_get_normal,
c: Capsule,
pos: Isometry3<f32>,
ray: Ray,
Expand All @@ -115,8 +115,8 @@ bench_method!(
);

bench_method!(
bench_ray_against_cone_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_cone_with_normal,
cast_ray_and_get_normal,
c: Cone,
pos: Isometry3<f32>,
ray: Ray,
Expand All @@ -125,8 +125,8 @@ bench_method!(
);

bench_method!(
bench_ray_against_cylinder_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_cylinder_with_normal,
cast_ray_and_get_normal,
c: Cylinder,
pos: Isometry3<f32>,
ray: Ray,
Expand All @@ -135,8 +135,8 @@ bench_method!(
);

bench_method!(
bench_ray_against_segment_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_segment_with_normal,
cast_ray_and_get_normal,
c: Segment,
pos: Isometry3<f32>,
ray: Ray,
Expand All @@ -145,8 +145,8 @@ bench_method!(
);

bench_method!(
bench_ray_against_triangle_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_triangle_with_normal,
cast_ray_and_get_normal,
c: Triangle,
pos: Isometry3<f32>,
ray: Ray,
Expand All @@ -155,18 +155,18 @@ bench_method!(
);

bench_method!(
bench_ray_against_convex_with_normal_uv,
cast_ray_and_get_normal_and_uv,
c: ConvexHull,
bench_ray_against_convex_with_normal,
cast_ray_and_get_normal,
c: ConvexPolyhedron,
pos: Isometry3<f32>,
ray: Ray,
max_time_of_impact: f32,
solid: bool
);

bench_method_gen!(
bench_ray_against_trimesh_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_trimesh_with_normal,
cast_ray_and_get_normal,
m: TriMesh = generate_trimesh_around_origin,
pos: Isometry3<f32> = generate,
ray: Ray = generate,
Expand Down
7 changes: 4 additions & 3 deletions crates/parry3d/benches/support_map/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::common::{generate, unref};
use na::{Isometry3, Vector3};
use parry3d::shape::SupportMap;
use parry3d::shape::{Ball, Capsule, Cone, ConvexHull, Cuboid, Cylinder, Segment, Triangle};
use parry3d::shape::{Ball, Capsule, Cone, Cuboid, Cylinder, Segment, Triangle};
use parry3d::shape::{ConvexPolyhedron, SupportMap};
use rand::SeedableRng;
use rand_isaac::IsaacRng;
use test::Bencher;
Expand Down Expand Up @@ -59,10 +59,11 @@ bench_method!(
m: Isometry3<f32>,
dir: Vector3<f32>
);

bench_method!(
bench_convex_support_map,
support_point,
c: ConvexHull,
c: ConvexPolyhedron,
m: Isometry3<f32>,
dir: Vector3<f32>
);

0 comments on commit 81229a5

Please sign in to comment.