淡水求咸

博客园已经停止更新,请移步 http://lovecjh.com/

导航

计算下电脑的运算速度

写下面程序来计算下我的电脑的运算速度:

#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亿次运算。

posted on 2012-03-26 20:27  深圳彦祖  阅读(301)  评论(0编辑  收藏  举报