From 77a622f2bb3356ee005a9413f6436373ec06efc2 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 8 Jul 2008 17:20:17 +0000 Subject: add Cholesky and eigensolver benchmark --- bench/benchCholesky.cpp | 132 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 bench/benchCholesky.cpp (limited to 'bench/benchCholesky.cpp') diff --git a/bench/benchCholesky.cpp b/bench/benchCholesky.cpp new file mode 100644 index 000000000..88b52eb4e --- /dev/null +++ b/bench/benchCholesky.cpp @@ -0,0 +1,132 @@ + +// g++ -DNDEBUG -O3 -I.. benchCholesky.cpp -o benchCholesky && ./benchCholesky +// options: +// -DBENCH_GSL -lgsl /usr/lib/libcblas.so.3 +// -DEIGEN_DONT_VECTORIZE +// -msse2 +// -DREPEAT=100 +// -DTRIES=10 +// -DSCALAR=double + +#include +#include +#include +using namespace Eigen; + +#ifndef REPEAT +#define REPEAT 10000 +#endif + +#ifndef TRIES +#define TRIES 4 +#endif + +typedef float Scalar; + +template +__attribute__ ((noinline)) void benchCholesky(const MatrixType& m) +{ + int rows = m.rows(); + int cols = m.cols(); + + int repeats = (REPEAT*1000)/(rows*rows); + + typedef typename MatrixType::Scalar Scalar; + typedef Matrix SquareMatrixType; + + MatrixType a = MatrixType::random(rows,cols); + SquareMatrixType covMat = a * a.adjoint(); + + BenchTimer timerNoSqrt, timerSqrt; + + Scalar acc = 0; + int r = ei_random(0,covMat.rows()-1); + int c = ei_random(0,covMat.cols()-1); + for (int t=0; t cholnosqrt(covMat); + acc += cholnosqrt.matrixL().coeff(r,c); + } + timerNoSqrt.stop(); + } + + for (int t=0; t chol(covMat); + acc += chol.matrixL().coeff(r,c); + } + timerSqrt.stop(); + } + + if (MatrixType::RowsAtCompileTime==Dynamic) + std::cout << "dyn "; + else + std::cout << "fixed "; + std::cout << covMat.rows() << " \t" + << (timerNoSqrt.value() * REPEAT) / repeats << "s \t" + << (timerSqrt.value() * REPEAT) / repeats << "s"; + + + #ifdef BENCH_GSL + if (MatrixType::RowsAtCompileTime==Dynamic) + { + timerSqrt.reset(); + + gsl_matrix* gslCovMat = gsl_matrix_alloc(covMat.rows(),covMat.cols()); + gsl_matrix* gslCopy = gsl_matrix_alloc(covMat.rows(),covMat.cols()); + + eiToGsl(covMat, &gslCovMat); + for (int t=0; t0; ++i) + benchCholesky(Matrix(dynsizes[i],dynsizes[i])); + + benchCholesky(Matrix()); + benchCholesky(Matrix()); + benchCholesky(Matrix()); + benchCholesky(Matrix()); + benchCholesky(Matrix()); + benchCholesky(Matrix()); + benchCholesky(Matrix()); + benchCholesky(Matrix()); + benchCholesky(Matrix()); + return 0; +} + -- cgit v1.2.3