mirror of
https://github.com/opencv/opencv.git
synced 2024-11-27 12:40:05 +08:00
Enhance cv::TickMeter to be able to get the last ellapsed time
This commit is contained in:
parent
450e741f8d
commit
679931dcde
@ -309,11 +309,12 @@ public:
|
||||
//! stops counting ticks.
|
||||
CV_WRAP void stop()
|
||||
{
|
||||
int64 time = cv::getTickCount();
|
||||
const int64 time = cv::getTickCount();
|
||||
if (startTime == 0)
|
||||
return;
|
||||
++counter;
|
||||
sumTime += (time - startTime);
|
||||
lastTime = time - startTime;
|
||||
sumTime += lastTime;
|
||||
startTime = 0;
|
||||
}
|
||||
|
||||
@ -341,6 +342,30 @@ public:
|
||||
return (double)getTimeTicks() / getTickFrequency();
|
||||
}
|
||||
|
||||
//! returns counted ticks of the last iteration.
|
||||
CV_WRAP int64 getLastTimeTicks() const
|
||||
{
|
||||
return lastTime;
|
||||
}
|
||||
|
||||
//! returns passed time of the last iteration in microseconds.
|
||||
CV_WRAP double getLastTimeMicro() const
|
||||
{
|
||||
return getLastTimeMilli()*1e3;
|
||||
}
|
||||
|
||||
//! returns passed time of the last iteration in milliseconds.
|
||||
CV_WRAP double getLastTimeMilli() const
|
||||
{
|
||||
return getLastTimeSec()*1e3;
|
||||
}
|
||||
|
||||
//! returns passed time of the last iteration in seconds.
|
||||
CV_WRAP double getLastTimeSec() const
|
||||
{
|
||||
return (double)getLastTimeTicks() / getTickFrequency();
|
||||
}
|
||||
|
||||
//! returns internal counter value.
|
||||
CV_WRAP int64 getCounter() const
|
||||
{
|
||||
@ -373,15 +398,17 @@ public:
|
||||
//! resets internal values.
|
||||
CV_WRAP void reset()
|
||||
{
|
||||
startTime = 0;
|
||||
sumTime = 0;
|
||||
counter = 0;
|
||||
sumTime = 0;
|
||||
startTime = 0;
|
||||
lastTime = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
int64 counter;
|
||||
int64 sumTime;
|
||||
int64 startTime;
|
||||
int64 lastTime;
|
||||
};
|
||||
|
||||
/** @brief output operator
|
||||
|
@ -78,6 +78,7 @@ int main()
|
||||
tm.start();
|
||||
// do something ...
|
||||
tm.stop();
|
||||
cout << "Last iteration: " << tm.getLastTimeSec() << endl;
|
||||
}
|
||||
cout << "Average time per iteration in seconds: " << tm.getAvgTimeSec() << endl;
|
||||
cout << "Average FPS: " << tm.getFPS() << endl;
|
||||
|
Loading…
Reference in New Issue
Block a user