在c语言中如何取得整个程序的执行时间?

如题所述

#include<stdio.h>
#include<time.h>
int main()
{
clock_t start,end;

start = clock(); //开始时,取得开始时间。

//你自己的代码

end = clock(); //结束时,取得结束时间

printf("Run time: %lf S",(double)(end-start)/CLOCKS_PER_SEC);
return 0;

}
温馨提示:内容为网友见解,仅供参考
第1个回答  2015-10-23
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int sum = 0;
int loops = 100000000;
clock_t start, end;
start = clock(); //记录开始时间
while (loops--)
sum += 1;
end = clock(); //结束时间
printf("%d loops spend %lf s", 1000000,(double)(end - start) / CLOCKS_PER_SEC);
return 0;
}
相似回答