首先在开头加上头文件#include <time.h>
然后使用a=clock();获得当然时间
#include <stdio.h>
#include <time.h>
int main(void)
{
int i=123456789;
clock_t start, end;
start = clock();
while(i--);
end = clock();
printf("The time was: %d\n", (end - start));//单位是毫秒,注意是%d,不再是%f
printf("The time was: %f\n", (double)(end - start) / CLK_TCK); //单位是秒
return 0;
}