From 33df5383cf10beed1eed8cb59d115d026d3ebef6 Mon Sep 17 00:00:00 2001 From: Cameron Hart Date: Thu, 11 Apr 2024 22:59:11 +1200 Subject: [PATCH] Add iai benches --- Cargo.toml | 7 ++++ benches/iai.rs | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 benches/iai.rs diff --git a/Cargo.toml b/Cargo.toml index ab3e8464..548e762b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,6 +61,9 @@ serde_json = "1.0" [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] criterion = { version = "0.5", features = ["html_reports"] } +[target.'cfg(target_os = "linux")'.dev-dependencies] +iai = { version = "0.1" } + [target.'cfg(target_arch = "wasm32")'.dev-dependencies] wasm-bindgen-test = "0.3.0" @@ -115,6 +118,10 @@ harness = false name = "vec4" harness = false +[[bench]] +name = "iai" +harness = false + [workspace] members = [ "codegen", diff --git a/benches/iai.rs b/benches/iai.rs new file mode 100644 index 00000000..a273d43d --- /dev/null +++ b/benches/iai.rs @@ -0,0 +1,109 @@ +use core::hint::black_box; +use iai; + +use glam::{BVec3A, BVec4A, Mat4, Quat, Vec3A, Vec4}; + +#[inline] +fn mat4() -> Mat4 { + Mat4::from_cols_array(&[ + 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, + ]) +} + +#[inline] +fn quat() -> Quat { + Quat::IDENTITY +} + +#[inline] +fn vec3a() -> Vec3A { + Vec3A::new(1.0, 2.0, 3.0) +} + +#[inline] +fn vec4() -> Vec4 { + Vec4::new(1.0, 2.0, 3.0, 4.0) +} + +fn iai_bench_mat4_determinant() -> f32 { + black_box(mat4()).determinant() +} + +fn iai_bench_mat4_inverse() -> Mat4 { + black_box(mat4()).inverse() +} + +fn iai_bench_mat4_transpose() -> Mat4 { + black_box(mat4()).transpose() +} + +fn iai_bench_mat4_mul_mat4() -> Mat4 { + black_box(mat4()) * black_box(mat4()) +} + +fn iai_bench_mat4_mul_vec4() -> Vec4 { + black_box(mat4()) * black_box(vec4()) +} + +fn iai_bench_quat_mul_quat() -> Quat { + black_box(quat()) * black_box(quat()) +} + +fn iai_bench_quat_mul_vec3a() -> Vec3A { + black_box(quat()) * black_box(vec3a()) +} + +fn iai_bench_vec3a_dot() -> f32 { + black_box(vec3a()).dot(black_box(vec3a())) +} + +fn iai_bench_vec3a_cross() -> Vec3A { + black_box(vec3a()).cross(black_box(vec3a())) +} + +fn iai_bench_vec3a_length() -> f32 { + black_box(vec3a()).length() +} + +fn iai_bench_vec3a_normalize() -> Vec3A { + black_box(vec3a()).normalize() +} + +fn iai_bench_vec3a_select() -> Vec3A { + Vec3A::select(black_box(BVec3A::TRUE), Vec3A::ONE, Vec3A::ZERO) +} + +fn iai_bench_vec4_dot() -> f32 { + black_box(vec4()).dot(black_box(vec4())) +} + +fn iai_bench_vec4_length() -> f32 { + black_box(vec4()).length() +} + +fn iai_bench_vec4_normalize() -> Vec4 { + black_box(vec4()).normalize() +} + +fn iai_bench_vec4_select() -> Vec4 { + Vec4::select(black_box(BVec4A::TRUE), Vec4::ONE, Vec4::ZERO) +} + +iai::main!( + iai_bench_mat4_determinant, + iai_bench_mat4_inverse, + iai_bench_mat4_mul_mat4, + iai_bench_mat4_mul_vec4, + iai_bench_mat4_transpose, + iai_bench_quat_mul_quat, + iai_bench_quat_mul_vec3a, + iai_bench_vec3a_dot, + iai_bench_vec3a_cross, + iai_bench_vec3a_length, + iai_bench_vec3a_normalize, + iai_bench_vec3a_select, + iai_bench_vec4_dot, + iai_bench_vec4_length, + iai_bench_vec4_normalize, + iai_bench_vec4_select, +);