mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Migrate Eigen benchmarks to the Google benchmark framework
libeigen/eigen!2132 Closes #3025 Co-authored-by: Rasmus Munk Larsen <rmlarsen@gmail.com>
This commit is contained in:
48
benchmarks/benchCholesky.cpp
Normal file
48
benchmarks/benchCholesky.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include <benchmark/benchmark.h>
|
||||
#include <Eigen/Core>
|
||||
#include <Eigen/Cholesky>
|
||||
|
||||
using namespace Eigen;
|
||||
|
||||
typedef float Scalar;
|
||||
|
||||
static void BM_LDLT(benchmark::State& state) {
|
||||
int n = state.range(0);
|
||||
typedef Matrix<Scalar, Dynamic, Dynamic> MatrixType;
|
||||
typedef Matrix<Scalar, Dynamic, Dynamic> SquareMatrixType;
|
||||
MatrixType a = MatrixType::Random(n, n);
|
||||
SquareMatrixType covMat = a * a.adjoint();
|
||||
int r = internal::random<int>(0, n - 1);
|
||||
int c = internal::random<int>(0, n - 1);
|
||||
Scalar acc = 0;
|
||||
for (auto _ : state) {
|
||||
LDLT<SquareMatrixType> cholnosqrt(covMat);
|
||||
acc += cholnosqrt.matrixL().coeff(r, c);
|
||||
benchmark::DoNotOptimize(acc);
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_LDLT)->RangeMultiplier(2)->Range(4, 1500);
|
||||
|
||||
static void BM_LLT(benchmark::State& state) {
|
||||
int n = state.range(0);
|
||||
typedef Matrix<Scalar, Dynamic, Dynamic> MatrixType;
|
||||
typedef Matrix<Scalar, Dynamic, Dynamic> SquareMatrixType;
|
||||
MatrixType a = MatrixType::Random(n, n);
|
||||
SquareMatrixType covMat = a * a.adjoint();
|
||||
int r = internal::random<int>(0, n - 1);
|
||||
int c = internal::random<int>(0, n - 1);
|
||||
Scalar acc = 0;
|
||||
for (auto _ : state) {
|
||||
LLT<SquareMatrixType> chol(covMat);
|
||||
acc += chol.matrixL().coeff(r, c);
|
||||
benchmark::DoNotOptimize(acc);
|
||||
}
|
||||
double cost = 0;
|
||||
for (int j = 0; j < n; ++j) {
|
||||
int rem = std::max(n - j - 1, 0);
|
||||
cost += 2 * (rem * j + rem + j);
|
||||
}
|
||||
state.counters["GFLOPS"] =
|
||||
benchmark::Counter(cost, benchmark::Counter::kIsIterationInvariantRate, benchmark::Counter::kIs1000);
|
||||
}
|
||||
BENCHMARK(BM_LLT)->RangeMultiplier(2)->Range(4, 1500);
|
||||
Reference in New Issue
Block a user