mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Reorganize benchmarks into subdirectories and clean up Eigen sources
libeigen/eigen!2176 Co-authored-by: Rasmus Munk Larsen <rmlarsen@gmail.com>
This commit is contained in:
3
benchmarks/Geometry/CMakeLists.txt
Normal file
3
benchmarks/Geometry/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
eigen_add_benchmark(bench_transforms bench_transforms.cpp)
|
||||
eigen_add_benchmark(bench_geometry bench_geometry.cpp)
|
||||
eigen_add_benchmark(bench_quatmul bench_quatmul.cpp)
|
||||
71
benchmarks/Geometry/bench_geometry.cpp
Normal file
71
benchmarks/Geometry/bench_geometry.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include <benchmark/benchmark.h>
|
||||
#include <Eigen/Geometry>
|
||||
|
||||
using namespace Eigen;
|
||||
|
||||
// Helper to get dimension from various transform types
|
||||
template <typename T>
|
||||
struct TransformDim {
|
||||
static constexpr int value = T::Dim;
|
||||
};
|
||||
|
||||
template <typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
|
||||
struct TransformDim<Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>> {
|
||||
static constexpr int value = Rows;
|
||||
};
|
||||
|
||||
template <typename Transformation, int N>
|
||||
static void BM_TransformData(benchmark::State& state) {
|
||||
typedef typename Transformation::Scalar Scalar;
|
||||
constexpr int Dim = TransformDim<Transformation>::value;
|
||||
Transformation t;
|
||||
if constexpr (std::is_same_v<Transformation, Matrix<Scalar, Dim, Dim>>) {
|
||||
t.setRandom();
|
||||
} else {
|
||||
Matrix<Scalar, Dim, Dim + 1> mat;
|
||||
mat.setRandom();
|
||||
t = Transformation(mat);
|
||||
}
|
||||
Matrix<Scalar, Dim, N> data;
|
||||
data.setRandom();
|
||||
for (auto _ : state) {
|
||||
data = t * data;
|
||||
benchmark::DoNotOptimize(data.data());
|
||||
}
|
||||
}
|
||||
|
||||
// For quaternion: apply per-column
|
||||
template <typename Scalar, int N>
|
||||
static void BM_QuatTransform(benchmark::State& state) {
|
||||
Quaternion<Scalar> q;
|
||||
q.setIdentity();
|
||||
Matrix<Scalar, 3, N> data;
|
||||
data.setRandom();
|
||||
for (auto _ : state) {
|
||||
for (int i = 0; i < N; ++i) data.col(i) = q * data.col(i);
|
||||
benchmark::DoNotOptimize(data.data());
|
||||
}
|
||||
}
|
||||
|
||||
// Use typedefs to avoid commas in macro arguments
|
||||
typedef Transform<float, 3, Isometry> Isometry3f_t;
|
||||
typedef Transform<float, 3, Affine> Affine3f_t;
|
||||
typedef Transform<float, 3, AffineCompact> AffineCompact3f_t;
|
||||
typedef Matrix<float, 3, 3> Matrix3f_t;
|
||||
|
||||
BENCHMARK(BM_TransformData<Isometry3f_t, 1>);
|
||||
BENCHMARK(BM_TransformData<Isometry3f_t, 4>);
|
||||
BENCHMARK(BM_TransformData<Isometry3f_t, 8>);
|
||||
BENCHMARK(BM_TransformData<Affine3f_t, 1>);
|
||||
BENCHMARK(BM_TransformData<Affine3f_t, 4>);
|
||||
BENCHMARK(BM_TransformData<Affine3f_t, 8>);
|
||||
BENCHMARK(BM_TransformData<AffineCompact3f_t, 1>);
|
||||
BENCHMARK(BM_TransformData<AffineCompact3f_t, 4>);
|
||||
BENCHMARK(BM_TransformData<AffineCompact3f_t, 8>);
|
||||
BENCHMARK(BM_TransformData<Matrix3f_t, 1>);
|
||||
BENCHMARK(BM_TransformData<Matrix3f_t, 4>);
|
||||
BENCHMARK(BM_TransformData<Matrix3f_t, 8>);
|
||||
|
||||
BENCHMARK(BM_QuatTransform<float, 1>);
|
||||
BENCHMARK(BM_QuatTransform<float, 4>);
|
||||
BENCHMARK(BM_QuatTransform<float, 8>);
|
||||
38
benchmarks/Geometry/bench_quatmul.cpp
Normal file
38
benchmarks/Geometry/bench_quatmul.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <benchmark/benchmark.h>
|
||||
#include <Eigen/Core>
|
||||
#include <Eigen/Geometry>
|
||||
|
||||
using namespace Eigen;
|
||||
|
||||
template <typename Quat>
|
||||
EIGEN_DONT_INLINE void quatmul_default(const Quat& a, const Quat& b, Quat& c) {
|
||||
c = a * b;
|
||||
}
|
||||
|
||||
template <typename Quat>
|
||||
EIGEN_DONT_INLINE void quatmul_novec(const Quat& a, const Quat& b, Quat& c) {
|
||||
c = internal::quat_product<0, Quat, Quat, typename Quat::Scalar>::run(a, b);
|
||||
}
|
||||
|
||||
template <typename Quat>
|
||||
static void BM_QuatMul_Default(benchmark::State& state) {
|
||||
Quat a(4, 1, 2, 3), b(2, 3, 4, 5), c;
|
||||
for (auto _ : state) {
|
||||
quatmul_default(a, b, c);
|
||||
benchmark::DoNotOptimize(c.coeffs().data());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Quat>
|
||||
static void BM_QuatMul_NoVec(benchmark::State& state) {
|
||||
Quat a(4, 1, 2, 3), b(2, 3, 4, 5), c;
|
||||
for (auto _ : state) {
|
||||
quatmul_novec(a, b, c);
|
||||
benchmark::DoNotOptimize(c.coeffs().data());
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK(BM_QuatMul_Default<Quaternionf>);
|
||||
BENCHMARK(BM_QuatMul_NoVec<Quaternionf>);
|
||||
BENCHMARK(BM_QuatMul_Default<Quaterniond>);
|
||||
BENCHMARK(BM_QuatMul_NoVec<Quaterniond>);
|
||||
43
benchmarks/Geometry/bench_transforms.cpp
Normal file
43
benchmarks/Geometry/bench_transforms.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <benchmark/benchmark.h>
|
||||
#include <Eigen/Core>
|
||||
#include <Eigen/Geometry>
|
||||
|
||||
using namespace Eigen;
|
||||
|
||||
template <typename Scalar, int Mode, int VSize>
|
||||
static void BM_TransformVec(benchmark::State& state) {
|
||||
typedef Transform<Scalar, 3, Mode> Trans;
|
||||
typedef Matrix<Scalar, VSize, 1> Vec;
|
||||
Trans t;
|
||||
t.setIdentity();
|
||||
Vec v;
|
||||
v.setRandom();
|
||||
for (auto _ : state) {
|
||||
v = t * v;
|
||||
benchmark::DoNotOptimize(v.data());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Scalar, int Mode>
|
||||
static void BM_TransformTransform(benchmark::State& state) {
|
||||
typedef Transform<Scalar, 3, Mode> Trans;
|
||||
Trans t1, t2;
|
||||
t1.setIdentity();
|
||||
t2.setIdentity();
|
||||
for (auto _ : state) {
|
||||
t2 = Trans(t1 * t2);
|
||||
benchmark::DoNotOptimize(t2.data());
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK(BM_TransformVec<float, Isometry, 3>);
|
||||
BENCHMARK(BM_TransformVec<float, Isometry, 4>);
|
||||
BENCHMARK(BM_TransformVec<float, Projective, 4>);
|
||||
BENCHMARK(BM_TransformVec<double, Isometry, 3>);
|
||||
BENCHMARK(BM_TransformVec<double, Isometry, 4>);
|
||||
BENCHMARK(BM_TransformVec<double, Projective, 4>);
|
||||
|
||||
BENCHMARK(BM_TransformTransform<float, Isometry>);
|
||||
BENCHMARK(BM_TransformTransform<float, Projective>);
|
||||
BENCHMARK(BM_TransformTransform<double, Isometry>);
|
||||
BENCHMARK(BM_TransformTransform<double, Projective>);
|
||||
Reference in New Issue
Block a user