• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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::{Vec3, Vec3A};
8 use std::ops::Mul;
9 use support::*;
10 
11 bench_binop!(
12     vec3a_mul_vec3a,
13     "vec3a mul vec3a",
14     op => mul,
15     from1 => random_vec3a,
16     from2 => random_vec3a
17 );
18 
19 #[inline]
vec3a_to_rgb_op(v: Vec3A) -> u3220 fn vec3a_to_rgb_op(v: Vec3A) -> u32 {
21     let (red, green, blue) = (v.min(Vec3A::ONE).max(Vec3A::ZERO) * 255.0).into();
22     (red as u32) << 16 | (green as u32) << 8 | (blue as u32)
23 }
24 
25 #[inline]
vec3a_deref(v: Vec3A) -> [f32; 3]26 fn vec3a_deref(v: Vec3A) -> [f32; 3] {
27     [v.x, v.y, v.z]
28 }
29 
30 #[inline]
vec3a_into_array(v: Vec3A) -> [f32; 3]31 fn vec3a_into_array(v: Vec3A) -> [f32; 3] {
32     v.into()
33 }
34 
35 #[inline]
vec3a_into_tuple(v: Vec3A) -> (f32, f32, f32)36 fn vec3a_into_tuple(v: Vec3A) -> (f32, f32, f32) {
37     v.into()
38 }
39 
40 #[inline]
vec3a_into_vec3(v: Vec3A) -> Vec341 fn vec3a_into_vec3(v: Vec3A) -> Vec3 {
42     v.into()
43 }
44 
45 bench_func!(
46 vec3a_to_vec3,
47 "vec3a into vec3",
48 op => vec3a_into_vec3,
49 from => random_vec3a
50 );
51 
52 bench_func!(
53 vec3a_to_rgb,
54 "vec3a to rgb",
55 op => vec3a_to_rgb_op,
56 from => random_vec3a
57 );
58 
59 bench_func!(
60 vec3a_to_array_deref,
61 "vec3a into array deref",
62 op => vec3a_deref,
63 from => random_vec3a
64 );
65 
66 bench_func!(
67 vec3a_to_array_into,
68 "vec3a into array fast",
69 op => vec3a_into_array,
70 from => random_vec3a
71 );
72 
73 bench_func!(
74 vec3a_to_tuple_into,
75 "vec3a into tuple fast",
76 op => vec3a_into_tuple,
77 from => random_vec3a
78 );
79 
80 euler!(vec3a_euler, "vec3a euler", ty => Vec3A, storage => Vec3A, zero => Vec3A::ZERO, rand => random_vec3a);
81 
82 bench_binop!(
83     vec3a_angle_between,
84     "vec3a angle_between",
85     op => angle_between,
86     from1 => random_vec3a,
87     from2 => random_vec3a
88 );
89 
90 bench_select!(
91     vec3a_select,
92     "vec3a select",
93     ty => Vec3A,
94     op => cmple,
95     from => random_vec3a
96 );
97 
98 criterion_group!(
99     benches,
100     vec3a_mul_vec3a,
101     vec3a_angle_between,
102     vec3a_euler,
103     vec3a_select,
104     vec3a_to_array_deref,
105     vec3a_to_array_into,
106     vec3a_to_rgb,
107     vec3a_to_tuple_into,
108     vec3a_to_vec3,
109 );
110 
111 criterion_main!(benches);
112