1 #[path = "support/macros.rs"]
2 #[macro_use]
3 mod macros;
4 mod support;
5
6 use criterion::{criterion_group, criterion_main, Criterion};
7 use glam::Affine3A;
8 use std::ops::Mul;
9 use support::*;
10
random_srt_affine3a(rng: &mut PCG32) -> Affine3A11 pub fn random_srt_affine3a(rng: &mut PCG32) -> Affine3A {
12 Affine3A::from_scale_rotation_translation(
13 random_nonzero_vec3(rng),
14 random_quat(rng),
15 random_vec3(rng),
16 )
17 }
18
19 bench_unop!(affine3a_inverse, "affine3a inverse", op => inverse, from => random_srt_affine3a);
20
21 bench_binop!(
22 affine3a_transform_point3,
23 "affine3a transform point3",
24 op => transform_point3,
25 from1 => random_srt_affine3a,
26 from2 => random_vec3
27 );
28
29 bench_binop!(
30 affine3a_transform_vector3,
31 "affine3a transform vector3",
32 op => transform_vector3,
33 from1 => random_srt_affine3a,
34 from2 => random_vec3
35 );
36
37 bench_binop!(
38 affine3a_transform_point3a,
39 "affine3a transform point3a",
40 op => transform_point3a,
41 from1 => random_srt_affine3a,
42 from2 => random_vec3a
43 );
44
45 bench_binop!(
46 affine3a_transform_vector3a,
47 "affine3a transform vector3a",
48 op => transform_vector3a,
49 from1 => random_srt_affine3a,
50 from2 => random_vec3a
51 );
52
53 bench_binop!(
54 affine3a_mul_affine3a,
55 "affine3a mul affine3a",
56 op => mul,
57 from => random_srt_affine3a
58 );
59
60 bench_binop!(affine3a_mul_mat4,
61 "affine3a mul mat4",
62 op => mul,
63 from1 => random_srt_affine3a,
64 from2 => random_srt_mat4
65 );
66
67 bench_binop!(
68 mat4_mul_affine3a,
69 "mat4 mul affine3a",
70 op => mul,
71 from1 => random_srt_mat4,
72 from2 => random_srt_affine3a
73 );
74
affine3a_from_srt(c: &mut Criterion)75 pub fn affine3a_from_srt(c: &mut Criterion) {
76 use glam::{Quat, Vec3};
77 const SIZE: usize = 1 << 13;
78 let mut rng = support::PCG32::default();
79 let inputs = criterion::black_box(
80 (0..SIZE)
81 .map(|_| {
82 (
83 random_nonzero_vec3(&mut rng),
84 random_quat(&mut rng),
85 random_vec3(&mut rng),
86 )
87 })
88 .collect::<Vec<(Vec3, Quat, Vec3)>>(),
89 );
90 let mut outputs = vec![Affine3A::IDENTITY; SIZE];
91 let mut i = 0;
92 c.bench_function("affine3a from srt", |b| {
93 b.iter(|| {
94 i = (i + 1) & (SIZE - 1);
95 unsafe {
96 let data = inputs.get_unchecked(i);
97 *outputs.get_unchecked_mut(i) =
98 Affine3A::from_scale_rotation_translation(data.0, data.1, data.2)
99 }
100 })
101 });
102 }
103
104 criterion_group!(
105 benches,
106 affine3a_from_srt,
107 affine3a_inverse,
108 affine3a_mul_affine3a,
109 affine3a_mul_mat4,
110 affine3a_transform_point3,
111 affine3a_transform_point3a,
112 affine3a_transform_vector3,
113 affine3a_transform_vector3a,
114 mat4_mul_affine3a,
115 );
116
117 criterion_main!(benches);
118