#include <stdio.h>
#include <time.h>
int main(){ 
  printf("hello word\n");
  printf("Time used = %.2lf\n", (double)clock() / CLOCKS_PER_SEC);
  return 0;
}

说明:(1)计时函数clock()返回程序目前为止运行的时间,以毫秒为单位。在程序结束之前调用它,便可获得整个程序的运行时间。这个时间除以常数CLOCKS_PER_SEC之后得到的值以“秒”为单位。
(2)在VC++6.0中time.h下宏定义的常量CLOCKS_PER_SEC,其值为1000。
#define CLOCKS_PER_SEC 1000
对于CLOCKS_PER_SEC,它用来表示一秒钟会有多少个时钟计时单元,时钟计时单元的长度为1毫秒,clock()/CLOCKS_PER_SEC就是将毫秒转化为秒。

 

更多推荐

C语言获取程序运行时间