Advertisement
Guest User

double-performance

a guest
Oct 5th, 2015
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <boost/random/mersenne_twister.hpp>
  2. #include <boost/random/uniform_int_distribution.hpp>
  3. #include <boost/timer/timer.hpp>
  4. #include "Eigen/Dense"
  5.  
  6. #define LENGTH 3
  7. int  main( int  argc, char  ** argv )
  8. { boost::random::mt19937 gen;
  9.   boost::random::uniform_int_distribution<> dist(1, 10);
  10.   typedef Eigen::Array<double,LENGTH,1>  Arr;
  11.   Arr five(5.0);
  12.   Arr ten(10.0);
  13.   Arr res(0.0);
  14.   const int loops = 100000;
  15.   { int j = LENGTH;
  16.     while (j--)
  17.     { ten(j) *= dist(gen);
  18.       five(j) *= dist(gen);
  19.     }
  20.   }
  21.   { boost::timer::auto_cpu_timer t;
  22.     int i = loops;
  23.     while (i--)
  24.     { res += res.max(ten.min(five)); }
  25.   }
  26.   res=0.0;
  27.   { boost::timer::auto_cpu_timer t;
  28.     int i = loops;
  29.     while (i--)
  30.     { int j=LENGTH;
  31.       while (j--)
  32.       { res(j) += std::max ( res(j), std::min (ten(j),five(j))); }
  33.     }
  34.   }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement