读书人

为什么VC6编译编译的程序比2005编译的

发布时间: 2012-03-11 18:15:38 作者: rapoo

为什么VC6编译编译的程序比2005编译的程序快呢
为什么为什么VC6编译编译的程序比2005编译的程序快
例如如下代码,6.0编译后运行实践4秒,2005编译后运行要12秒。编译都是用的默认环境。

以前在6.0下编译的计算程序,搬到2005下运行得比蜗牛还慢。Wandering!!!!!!
有没有人遇到过这种问题?给解释一下。



#include <iostream>
#include <math.h>
#include <time.h>

#define NUM 100000000

using namespace std;

int main()
{
time_t begin_time = 0;
time(&begin_time);
cout<<"Begin"<<endl;

int i = 0;
float *pVal = new float[NUM];
if(!pVal)
return 0;
for (i = 0; i < NUM; i++)
{
pVal[i] = i+1;
}

for(i = 0; i < NUM; i++)
pVal[i] = sqrt(pVal[i]);

delete []pVal;

time_t end_time;
time(&end_time);
cout<<"total used time:"<<end_time-begin_time<<endl;

return 0;
}

[解决办法]
打开vs2005的 /fp:fast 试试呢?

[解决办法]
恩,经过vc和2005下的对比测试发现,性能差异不在第一个for循环,而是在第二个循环求sqrt函数中。然后按照loops的建议,打开/fp:fast选项,二者的性能就基本上是一样的了。

读书人网 >C++

热点推荐