How to do it...

In order to measure the execution time of a function or a portion of code, there exists a very convenient OpenCV function called cv::getTickCount(). This function gives you the number of clock cycles that have occurred since the last time you started your computer. Since we want the execution time of a code portion given in seconds, we use another method, cv::getTickFrequency(). This gives us the number of cycles per second. The usual pattern to be used in order to obtain the computational time of a given function (or a portion of code) would be as follows:

  1. Get the start time point:
const int64 start = cv::getTickCount(); 
  1. Call your functions or the code you want to measure:
colorReduce(image); // a function call 
  1. Calculate the execution time, getting the actual time point minus the start point and dividing it by the number of cycles per second:
// elapsed time in seconds 
double duration = (cv::getTickCount()-start)/cv::getTickFrequency();