bench_reverse.cpp
Go to the documentation of this file.
00001 
00002 #include <iostream>
00003 #include <Eigen/Core>
00004 #include <bench/BenchUtil.h>
00005 using namespace Eigen;
00006 
00007 #ifndef REPEAT
00008 #define REPEAT 100000
00009 #endif
00010 
00011 #ifndef TRIES
00012 #define TRIES 20
00013 #endif
00014 
00015 typedef double Scalar;
00016 
00017 template <typename MatrixType>
00018 __attribute__ ((noinline)) void bench_reverse(const MatrixType& m)
00019 {
00020   int rows = m.rows();
00021   int cols = m.cols();
00022   int size = m.size();
00023 
00024   int repeats = (REPEAT*1000)/size;
00025   MatrixType a = MatrixType::Random(rows,cols);
00026   MatrixType b = MatrixType::Random(rows,cols);
00027 
00028   BenchTimer timerB, timerH, timerV;
00029 
00030   Scalar acc = 0;
00031   int r = internal::random<int>(0,rows-1);
00032   int c = internal::random<int>(0,cols-1);
00033   for (int t=0; t<TRIES; ++t)
00034   {
00035     timerB.start();
00036     for (int k=0; k<repeats; ++k)
00037     {
00038       asm("#begin foo");
00039       b = a.reverse();
00040       asm("#end foo");
00041       acc += b.coeff(r,c);
00042     }
00043     timerB.stop();
00044   }
00045 
00046   if (MatrixType::RowsAtCompileTime==Dynamic)
00047     std::cout << "dyn   ";
00048   else
00049     std::cout << "fixed ";
00050   std::cout << rows << " x " << cols << " \t"
00051             << (timerB.value() * REPEAT) / repeats << "s "
00052             << "(" << 1e-6 * size*repeats/timerB.value() << " MFLOPS)\t";
00053 
00054   std::cout << "\n";
00055   // make sure the compiler does not optimize too much
00056   if (acc==123)
00057     std::cout << acc;
00058 }
00059 
00060 int main(int argc, char* argv[])
00061 {
00062   const int dynsizes[] = {4,6,8,16,24,32,49,64,128,256,512,900,0};
00063   std::cout << "size            no sqrt                           standard";
00064 //   #ifdef BENCH_GSL
00065 //   std::cout << "       GSL (standard + double + ATLAS)  ";
00066 //   #endif
00067   std::cout << "\n";
00068   for (uint i=0; dynsizes[i]>0; ++i)
00069   {
00070     bench_reverse(Matrix<Scalar,Dynamic,Dynamic>(dynsizes[i],dynsizes[i]));
00071     bench_reverse(Matrix<Scalar,Dynamic,1>(dynsizes[i]*dynsizes[i]));
00072   }
00073 //   bench_reverse(Matrix<Scalar,2,2>());
00074 //   bench_reverse(Matrix<Scalar,3,3>());
00075 //   bench_reverse(Matrix<Scalar,4,4>());
00076 //   bench_reverse(Matrix<Scalar,5,5>());
00077 //   bench_reverse(Matrix<Scalar,6,6>());
00078 //   bench_reverse(Matrix<Scalar,7,7>());
00079 //   bench_reverse(Matrix<Scalar,8,8>());
00080 //   bench_reverse(Matrix<Scalar,12,12>());
00081 //   bench_reverse(Matrix<Scalar,16,16>());
00082   return 0;
00083 }
00084 


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:30