mirror of
https://gitlab.com/libeigen/eigen.git
synced 2024-12-21 07:19:46 +08:00
2ee68a074e
Finally the importing macro is named EIGEN_BASIC_PUBLIC_INTERFACE because it does not only import the ei_traits, it also makes the base class a friend, etc.
60 lines
1.5 KiB
C++
60 lines
1.5 KiB
C++
|
|
enum {LazyEval, EarlyEval, OmpEval};
|
|
|
|
template<int Mode, typename MatrixType>
|
|
void benchBasic_loop(const MatrixType& I, MatrixType& m, int iterations) __attribute__((noinline));
|
|
|
|
template<int Mode, typename MatrixType>
|
|
void benchBasic_loop(const MatrixType& I, MatrixType& m, int iterations)
|
|
{
|
|
for(int a = 0; a < iterations; a++)
|
|
{
|
|
if (Mode==LazyEval)
|
|
{
|
|
asm("#begin_bench_loop LazyEval");
|
|
if (MatrixType::SizeAtCompileTime!=Eigen::Dynamic) asm("#fixedsize");
|
|
m = (I + 0.00005 * (m + m.lazyProduct(m))).eval();
|
|
}
|
|
else if (Mode==OmpEval)
|
|
{
|
|
asm("#begin_bench_loop OmpEval");
|
|
if (MatrixType::SizeAtCompileTime!=Eigen::Dynamic) asm("#fixedsize");
|
|
m = (I + 0.00005 * (m + m.lazyProduct(m))).evalOMP();
|
|
}
|
|
else
|
|
{
|
|
asm("#begin_bench_loop EarlyEval");
|
|
if (MatrixType::SizeAtCompileTime!=Eigen::Dynamic) asm("#fixedsize");
|
|
m = I + 0.00005 * (m + m * m);
|
|
}
|
|
asm("#end_bench_loop");
|
|
}
|
|
}
|
|
|
|
template<int Mode, typename MatrixType>
|
|
double benchBasic(const MatrixType& mat, int size, int tries) __attribute__((noinline));
|
|
|
|
template<int Mode, typename MatrixType>
|
|
double benchBasic(const MatrixType& mat, int iterations, int tries)
|
|
{
|
|
const int rows = mat.rows();
|
|
const int cols = mat.cols();
|
|
|
|
MatrixType I(rows,cols);
|
|
MatrixType m(rows,cols);
|
|
|
|
initMatrix_identity(I);
|
|
|
|
Eigen::BenchTimer timer;
|
|
for(uint t=0; t<tries; ++t)
|
|
{
|
|
initMatrix_random(m);
|
|
timer.start();
|
|
benchBasic_loop<Mode>(I, m, iterations);
|
|
timer.stop();
|
|
cerr << m;
|
|
}
|
|
return timer.value();
|
|
};
|
|
|