求程序执行时间的函数
想知道一个程序运行的时间,但不知道是那个函数,求高手帮忙啊!
[解决办法]
clock_t 和 clock()函数(包含time.h)
clock_t time;
......
......
......
time = clock();
double start_time = (double)time;
......
time = clock();
double end_time = (double)time;
double timeSpend = end_time - start_time;
[解决办法]
unsigned long startime= GetTickCount();Sleep(3000);unsigned long time=GetTickCount()-startime;printf("%d",time);
[解决办法]
AME clock - Determine processor timeSYNOPSIS #include <time.h> clock_t clock(void);DESCRIPTION The clock() function returns an approximation of processor time used by the program.RETURN VALUE The value returned is the CPU time used so far as a clock_t; to get the number of seconds used, divide by CLOCKS_PER_SEC. If the processor time used is not available or its value cannot be represent
[解决办法]
说实话,CPU时间不能拿来评价程序的real time, 多核CPU或者其他技术什么的,CPU根本不是评价标准.
建议直接获取时间差,哪一个足够精确我也不知道.
owenliang@linux-7lsl:~/csdn/src> time ./main
asdf
asdf
max_chars : 4
0 0 0
real 0m1.528s
user 0m0.000s
sys 0m0.000s
[解决办法]
gettimeofday还不错,精确到微妙。
owenliang@linux-7lsl:~/csdn/src> ./mainasdfasdfmax_chars : 4 real time : 0 secs 717 msecs owenliang@linux-7lsl:~/csdn/src> time ./mainasdfasdfasdfasdfmax_chars : 4 real time : 1 secs 344 msecs real 0m1.346suser 0m0.000ssys 0m0.000sowenliang@linux-7lsl:~/csdn/src>