搜索
写经验 领红包
 > 影视

c语言中clock函数的使用(c语言 clock())

C语言库函数之clock()详解

原函数:

clock_t clock(void)

参数:

NA

返回值:

函数返回程序启动以来经过的时钟滴答数。失败时,函数返回值-1。

如何使用clock() 函数:

include <stdio.h>

int main() {

clock_t start_t, end_t, total_t;

int i;

start_t = clock();

printf(&34;, start_t);

printf(&34;, start_t);

for(i=0; i< 100000000; i++) {

}

end_t = clock();

printf(&34;, end_t);

total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;

printf(&34;, total_t );

printf(&34;);

return(0);

}

编译和运行上面的程序,产生如下结果:

Line 1 - Starting of the program, start_t = 0

Line 2 - Going to scan a big loop, start_t = 0

Line 3 - End of the big loop, end_t = 400000

Line 4 - Total time taken by CPU: 0.000000

Line 5 - Exiting of the program...

温馨提示:通过以上关于C语言库函数之clock()详解内容介绍后,相信大家有新的了解,更希望可以对你有所帮助。