计算我的程序的执行时间

时间:2013-07-19 05:29:15

标签: time execution

所以在我的图像处理项目中,我正在使用gettickcount()来计算每个帧处理所需的平均时间。但是,为了速度,我选择处理所有其他帧。从理论上讲,程序应该运行得更快,而且确实如此。但是,我从gettickcount得到的值保持不变。这让我相信gettickcount函数仍在计算程序未处理图像的刻度。

while(capture.grab())
{
    int64 t = getTickCount();

    if(count == 0) //count is each image number. this segment processes the first image
    {

    }

    if(count % 2 == 1) //processes every other image
    {

    }
}

getTickCount函数是否仍然计算if(count%2 == 1)的滴答数,即使它没有被使用?

谢谢!

2 个答案:

答案 0 :(得分:0)

是。无论“count”的值如何,您都会在while循环的每次传递中调用getTickCount。

尝试:

while(capture.grab())
{
    int64 t = 0;

    if(count == 0) //count is each image number. this segment processes the first image
    {
      t = getTickCount();
    }
    if(count % 2 == 1) //processes every other image
    {
      t = getTickCount();
    }
}

答案 1 :(得分:0)

#include<stdio.h>
#include<time.h>

int main()
{

clock_t start = clock();

//write your code here, and this will calculate the execution time of the code...

clock_t ends = clock();

printf("run time: %.5f \n", ((double)(ends - 

start)) / CLOCKS_PER_SEC);

return 0;

}