VS2008 から VS2012 に移行すると、VS2012 バージョンのパフォーマンスが非常に遅くなります。
問題は、入力ストリームの抽出演算子にあります。istream& operator>> (float& val); istream& operator>> (double& val);
テキスト ファイルに対するこれらの関数は、VS2012 では 2 倍遅くなります。
たとえば、次のコードは、VS2012 では 3.75 秒、VS2008 ではわずか 1.25 秒を取得します。
なぜか教えてくれますか?
前もって感謝します。
#include "stdafx.h"
#include <fstream>
#include <sstream>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <sstream>
#define FILE_NAME "D:\\test_Roadmap.txt"
const int NB_VALUE = 1000000;
const int NB_MESURE = 20;
int _tmain(int argc, _TCHAR* argv[])
{
std::cout<<"ecriture"<<std::endl;
//ecriture
{
std::ofstream ostream (FILE_NAME);
float val = 0.f;
for (int ii=0; ii<NB_VALUE; ii++)
{
ostream << val;
ostream << " ";
val += 0.04f;
}
}
std::cout<<"lecture"<<std::endl;
//lecture
double texec = 0;
for (int iMesure=0; iMesure<NB_MESURE; iMesure++)
{
std::ifstream istream (FILE_NAME);
float val = 0;
time_t tbegin1 = time(NULL);
for (int ii=0; ii<NB_VALUE; ii++)
{
istream>> val;
}
time_t tbegin2 = time(NULL);
texec += difftime(tbegin2,tbegin1);
}
texec /= NB_MESURE;
std::ostringstream oss1;
oss1 << texec;
std::string s1 = std::string(" read : ") + oss1.str() + std::string(" in s");
std::cout<<s1<<std::endl;
float a;
std::cin>>a;
return 0;
}