Calculating time taken by the code

How to calculate the time of execution of the code???

Here is a small code to make use of "time.h" for tracking the time of execution.

Example 1:

------------
    #include <time.h>

    ...***...***...***...

    clock_t start, end;
    double elapsed;
    start = clock();
    
    /* Your code    */
    
    end = clock();
    elapsed = ((double) (end - start)) / CLOCKS_PER_SEC;
    std::cout<<elapsed;
------------

Example 2: Doing in OpenCV

------------
double t = (double)getTickCount(); 
// do something ... 
t = ((double)getTickCount() - t)/getTickFrequency(); 
std::cout << "Times passed in seconds: " << t << std::endl;
------------

2 comments: