#include "time.h"
clock_t t_start,t_stop;
double time_spend;
// the operations you want do
... ...
... ...
t_stop=clock();
time_spend=(double)(t_stop-t_start)/CLOCKS_PER_SEC;
printf("the time spend is %d s\n", time_spend);
timer on cuda
以下是在cuda sdk例子中找到的相关计时程序,测试过可以用,但是关于shrQAStart我还没有大概明白是肿么回事,先拿来备份一下,以备之后忘了。其中win32调试需要加入cutil32D.lib;shrUtils32D.lib两个库,x64调试需要加入cutil64D.lib;shrUtils64D.lib
#include <cutil_inline.h>
#include <shrQATest.h>
main(int argc, char** argv)
{
shrQAStart(argc, argv);
// start the timer
unsigned int timer = 0;
cutilCheckError( cutCreateTimer( &timer));
cutilCheckError( cutStartTimer( timer));
// operations
....
...
...
//*stop & delete a time clock
cutilCheckError( cutStopTimer( timer));
printf( "Processing time(cutTimer): %f (ms)\n", cutGetTimerValue( timer));
cutilCheckError( cutDeleteTimer( timer));
shrQAFinishExit(argc, (const char **)argv, 1 );
}
Ps:用clock和timer得到的时间不是很一样,期待找到两者的区别~~~