1 #ifndef OPENCV_CUDA_SAMPLES_TICKMETER_ 2 #define OPENCV_CUDA_SAMPLES_TICKMETER_ 3 4 class CV_EXPORTS TickMeter 5 { 6 public: 7 TickMeter(); 8 void start(); 9 void stop(); 10 11 int64 getTimeTicks() const; 12 double getTimeMicro() const; 13 double getTimeMilli() const; 14 double getTimeSec() const; 15 int64 getCounter() const; 16 17 void reset(); 18 private: 19 int64 counter; 20 int64 sumTime; 21 int64 startTime; 22 }; 23 24 std::ostream& operator << (std::ostream& out, const TickMeter& tm); 25 26 TickMeter()27TickMeter::TickMeter() { reset(); } getTimeTicks() const28int64 TickMeter::getTimeTicks() const { return sumTime; } getTimeMicro() const29double TickMeter::getTimeMicro() const { return (double)getTimeTicks()/cv::getTickFrequency(); } getTimeMilli() const30double TickMeter::getTimeMilli() const { return getTimeMicro()*1e-3; } getTimeSec() const31double TickMeter::getTimeSec() const { return getTimeMilli()*1e-3; } getCounter() const32int64 TickMeter::getCounter() const { return counter; } reset()33void TickMeter::reset() {startTime = 0; sumTime = 0; counter = 0; } 34 start()35void TickMeter::start(){ startTime = cv::getTickCount(); } stop()36void TickMeter::stop() 37 { 38 int64 time = cv::getTickCount(); 39 if ( startTime == 0 ) 40 return; 41 ++counter; 42 sumTime += ( time - startTime ); 43 startTime = 0; 44 } 45 operator <<(std::ostream & out,const TickMeter & tm)46std::ostream& operator << (std::ostream& out, const TickMeter& tm) { return out << tm.getTimeSec() << "sec"; } 47 48 #endif 49