View difference between Paste ID: 2Bf1mQnx and 11XzzNFs
SHOW: | | - or go back to the newest paste.
1
#include <chrono>
2
#include <Eigen/Dense>
3
4
5
#define START_TIMER(start)  auto start = std::chrono::high_resolution_clock::now();
6
7
#define STOP_TIMER_MILLI( _count_, start)  \
8
    auto _count_ = std::chrono::duration<double,std::milli>(std::chrono::high_resolution_clock::now() - start ).count();
9
10
class CPUTimer{
11
12
public:
13
    using ClockType = std::chrono::high_resolution_clock;
14
15
    inline void start(){
16
        m_start = ClockType::now();
17
    }
18
19
    /** returns elapsed time in nanosecond*/
20
    inline double elapsed(){
21
        return std::chrono::duration<double,std::nano >(ClockType::now()-m_start).count();
22
    }
23
    /** returns elapsed time in second*/
24
    inline double elapsedSec(){
25
        return std::chrono::duration<double,std::ratio<1> >(ClockType::now()-m_start).count();
26
    }
27
    /** returns elapsed time in minutes*/
28
    inline double elapsedMin(){
29
        return std::chrono::duration<double,std::ratio<60> >(ClockType::now()-m_start).count();
30
    }
31
32
    /** returns elapsed time in millisecond*/
33
    inline double elapsedMilliSec(){
34
         return std::chrono::duration<double,std::milli>(ClockType::now()-m_start).count();
35
    }
36
37
private:
38
    std::chrono::time_point<ClockType> m_start;
39
};
40
41
int  main( int  argc, char  ** argv ){
42
43
44
45
    using Idx = Eigen::Array<long long int,3,1>  ;
46
47-
    Idx max(4,3,9);
47+
48-
    Idx idx(-1,5,10);
48+
    srand(5);
49-
    Idx t(0,0,0);
49+
50
    EIGEN_ASM_COMMENT("BEGIN1");
51-
    auto loops = 100000UL;
51+
52
        idx.setRandom();
53
        t += zero.max(max.min(idx));
54
    }
55
    EIGEN_ASM_COMMENT("END1");
56
57
    STOP_TIMER_MILLI(count,start)
58
    std::cout << "Eigen3: time: " << count << " ms " << t <<  std::endl;
59
60
    t.setZero();
61
    srand(5);
62
    START_TIMER(start2)
63
    EIGEN_ASM_COMMENT("BEGIN2");
64-
    t(0) += std::max(   std::min( max(0), idx(0)),  0LL   );
64+
65-
    t(1) += std::max(   std::min( max(1), idx(1)),  0LL   );
65+
        idx.setRandom();
66-
    t(2) += std::max(   std::min( max(2), idx(2)),  0LL   );
66+
        t(0) += std::max(   std::min( max(0), idx(0)),  0LL   );
67
        t(1) += std::max(   std::min( max(1), idx(1)),  0LL   );
68
        t(2) += std::max(   std::min( max(2), idx(2)),  0LL   );
69
    }
70
    STOP_TIMER_MILLI(count2,start2)
71
    EIGEN_ASM_COMMENT("END2");
72
    std::cout << "Seperate: time: " << count2 << " ms " << t << std::endl;
73
74
}