cloct_t计时用法

用到了程序的运行效率,  写了个计算时间的方法,

但是加上sleep(1)后,不起作用,不知道为什么

但是可以起到计算时间的作用;

另外time  ./a.out   也可以计算时间

 44 #include <stdio.h>
 45 #include <stdlib.h>
 46 #include <time.h>
 47 //#include <dos.h>
 48
 49 int main(int argc, char *argv[])
 50 {
 51     double count = 0;
 52     clock_t start, end;
 53     start = clock();
 54     printf("aaaaaaaaaaa %ld\n", (long int)start);
 55 //  sleep(1);
 56     long int i = 10000000;;
 57     while(i>0)
 58         i--;
 59     end = clock();
 60     printf("bbbbbbbbbb:%ld\n", (long int)end);
 61     printf("CLOCKS_PRE_SEC %ld \n", CLOCKS_PER_SEC);
 62     count = (double)(end - start) * 1000/((double)CLOCKS_PER_SEC);
 63     printf("The time was: %f min sec\n", count );//(double)(end - start)/(double)CLOCKS_PER_SEC);// / CLK_TCK);
 64     return 0;
 65 }

./a.out
aaaaaaaaaaa 0
bbbbbbbbbb:20000
CLOCKS_PRE_SEC 1000000
The time was: 20.000000 min sec
time ./a.out

aaaaaaaaaaa 0
bbbbbbbbbb:20000
CLOCKS_PRE_SEC 1000000
The time was: 20.000000 min sec

real 0m0.054s
user 0m0.028s
sys 0m0.000s

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

为伊痴狂

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值