CCS5.5环境下使用clock()函数测试程序段运行时间

来源:互联网 发布:将拍成网络剧的小说 编辑:程序博客网 时间:2024/06/06 14:17

1、Ctrl+B 编译程序后 F11下载程序

2、Run->Clock->enable

3、F8运行程序

附程序:

#include<stdio.h>#include<time.h>int main(void){unsigned int a = 10,b = 20,c;clock_t start,stop, overhead,cycles;start = clock();stop = clock();overhead = stop - start;start = clock();        //测试代码开始c = a + b;c++;        //测试代码结束stop = clock();cycles = stop - start - overhead;printf("cycles: %d\n",cycles);printf("times: %.2f us with CPU 456MHz.\n",((float) cycles /(float)456));return 0;}

运行结果:




0 0
原创粉丝点击