Merge pull request #26212 from jamacias:feature/TickMeter-lasttime

Enhance cv::TickMeter to be able to get the last elapsed time
This commit is contained in:
Alexander Smorkalov 2024-10-14 07:56:24 +03:00 committed by GitHub
commit 1909ac8650
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 5 deletions

View File

@ -340,11 +340,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;
}
@ -372,6 +373,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
{
@ -404,15 +429,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

View File

@ -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;