C语言中的测量程序运行时间的函数

来源:互联网 发布:专业注册会员软件 编辑:程序博客网 时间:2024/04/29 19:13
计时单位用秒:
#include   <time.h>
time_t   start   =   time(   NULL   );
....
printf(   "消耗了%d秒/n ",   time(NULL)   -   start   );

计时单位用豪秒:
#include   <time.h>
struct   timeb   start,   end;
ftime(   &start   );
....
ftime(   &end   );
printf(   "消耗了%d.%03u秒/n ",   end.time   -   start.time,   end.millitm   -   start.millitm   );  
原创粉丝点击