반응형

Function execution time can be measured by counting ticks after a certain event (for example, when the machine was turned on).

Below code shows how to do this.


getTickCount()나 TickMeter 클래스를 이용해 실행 시간을 계산 할 수 있다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <opencv2/opencv.hpp>
 
using namespace std;
using namespace cv;
 
int main(int argc, char** argv)
{
    RNG rng(getTickCount());
    Mat mat(300400, CV_8SC3);
    
    double start =  (double)getTickCount(); // Returns the number of ticks.
    rng.fill(mat, RNG::UNIFORM, Scalar::all(0), Scalar::all(255));
    // getTickFrequency() - Returns the number of ticks per second.
    double duration = ((double)getTickCount() - start) / getTickFrequency();
    cout << "Duration measured by getTickCount(): " << duration << endl;
    imshow("getTickCount", mat);
 
    // TickMeter class computes passing time by counting the number of ticks per second.
    TickMeter tm;
    tm.start(); // Starts counting ticks.
    rng.fill(mat, RNG::UNIFORM, Scalar::all(0), Scalar::all(255));
    tm.stop(); // Stops counting ticks.
    // Returns passed time in seconds.
    cout << "Duration measured by TickMeter: " << tm.getTimeSec() << endl;
    imshow("TickMeter", mat);
 
    waitKey(0);
 
    return 0;
}
cs








반응형
Posted by J-sean
: