关于time_t,clock_t ,time(),clock(),CLK_TCK, CLOCKS_PER_SEC 的使用
2007-03-29 21:28
ISO/IEC 9899:1999 标准中有一个宏: CLOCKS_PER_SEC
<1> tc2 中的 time.h:没有 CLOCKS_PER_SEC,有一个 CLK_TCK #define CLK_TCK 18.2 <2> gcc 中的 time.h:#define CLOCKS_PER_SEC ((clock_t)1000) #define CLK_TCK CLOCKS_PER_SEC
time返回从1970年1月1日到现在的秒数,是实际时间;
clock()得到的是毫秒做单位的,time()得到的是秒做单位的。
函数名: clock 功 能: 确定处理器时间 用 法: clock_t clock(void); 程序例: #include <time.h> #include <stdio.h> #include <dos.h> int main(void) { clock_t start, end; start = clock(); delay(2000); //MS VC 6.0 中可用_sleep() 代替delay,header:stdlib.h/iostream或Sleep()
//,header:windows.h end = clock(); printf("The time was: %f/n", (end - start) / CLK_TCK); return 0; }
函数名: time 功 能: 取一天的时间 用 法: logn time(long *tloc); 程序例: #include #include #include int main(void) { time_t t; t = time(NULL); printf("The number of seconds since January 1, 1970 is %ld",t); return 0; }
|
转载http://hi.baidu.com/sysucs/blog/item/3b9852365e8d06dca3cc2bd1.html