计算下电脑的运算速度
写下面程序来计算下我的电脑的运算速度:
#include <stdio.h>
#include <time.h>
void Printlocaltime(void)
{
struct tm *timeptr;
time_t secsnow;
time(&secsnow);
timeptr=localtime(&secsnow);
printf("The date is %d-%d-20%02d\n",
(timeptr->tm_mon)+1,
(timeptr->tm_mday),
(timeptr->tm_year)-100);
printf("Local time is %02d:%02d:%02d\n",
(timeptr->tm_hour),
(timeptr->tm_min),
(timeptr->tm_sec));
}
int main()
{
Printlocaltime();
for(int i=0;i<1000000000;i++)
{}
printf("\n\n");
Printlocaltime();
return 0;
}
运行结果:
The date is 3-26-2012
Local time is 20:05:30
The date is 3-26-2012
Local time is 20:05:34
显然在0.4s内进行了10亿次运算,所以1s的会进行25亿次运算。