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;
}
运行结果: