Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <chrono>
- #include <Eigen/Dense>
- #define START_TIMER(start) auto start = std::chrono::high_resolution_clock::now();
- #define STOP_TIMER_MILLI( _count_, start) \
- auto _count_ = std::chrono::duration<double,std::milli>(std::chrono::high_resolution_clock::now() - start ).count();
- class CPUTimer{
- public:
- using ClockType = std::chrono::high_resolution_clock;
- inline void start(){
- m_start = ClockType::now();
- }
- /** returns elapsed time in nanosecond*/
- inline double elapsed(){
- return std::chrono::duration<double,std::nano >(ClockType::now()-m_start).count();
- }
- /** returns elapsed time in second*/
- inline double elapsedSec(){
- return std::chrono::duration<double,std::ratio<1> >(ClockType::now()-m_start).count();
- }
- /** returns elapsed time in minutes*/
- inline double elapsedMin(){
- return std::chrono::duration<double,std::ratio<60> >(ClockType::now()-m_start).count();
- }
- /** returns elapsed time in millisecond*/
- inline double elapsedMilliSec(){
- return std::chrono::duration<double,std::milli>(ClockType::now()-m_start).count();
- }
- private:
- std::chrono::time_point<ClockType> m_start;
- };
- int main( int argc, char ** argv ){
- using Idx = Eigen::Array<long long int,3,1> ;
- Idx max(4,3,9);
- Idx idx(-1,5,10);
- Idx t(0,0,0);
- auto loops = 100000UL;
- START_TIMER(start)
- Idx zero(0,0,0);
- for(auto k=0; k<loops;++k){
- t += zero.max(max.min(idx));
- }
- STOP_TIMER_MILLI(count,start)
- std::cout << "Eigen3: time: " << count << " ms " << t << std::endl;
- t.setZero();
- START_TIMER(start2)
- for(auto k=0; k<loops;++k){
- t(0) += std::max( std::min( max(0), idx(0)), 0LL );
- t(1) += std::max( std::min( max(1), idx(1)), 0LL );
- t(2) += std::max( std::min( max(2), idx(2)), 0LL );
- }
- STOP_TIMER_MILLI(count2,start2)
- std::cout << "Seperate: time: " << count2 << " ms " << t << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement