运算符>>(istream&,double)VC10 / VC11的性能

时间:2013-03-04 11:41:19

标签: visual-studio-2010 performance visual-studio-2012

从VC10切换到VC11在读取double个数字的文件时,我发现性能下降了10倍:

#include <iostream>

int main() {
  double sum = 0, x;
  for(int i=0; i<1000000; i++){
    std::cin >> x;
    sum += x;
  }
  std::cerr << sum << std::endl;
  return 0;
}

我在Developer Studio中构建了可执行文件,以便环境最多选择发布模式中的选项。

任何人都可以证实吗? 可能是什么问题呢?可能与locale相关吗?

提前感谢,

andreas

1 个答案:

答案 0 :(得分:0)

*由于某些原因我的上一个答案被删除了(我承认第一句话有点令人困惑,因为当它得到更好的结果时笨拙的编辑)

实际上,对我而言,表现大致相同。

VC11写入/读取1M双打 - &gt; 6.600 / 3.562秒
VC10写入/读取1M双打 - &gt; 6.266 / 3.606秒

所以在我的实验中,从vc11中的文件读取双打是aprox。与vc10相同的性能。 Codesample:

int _tmain(int argc, _TCHAR* argv[])
{
  auto x = 0.0;
  auto numberofdoubles = 1000000;
  auto filename = "C:\\double.txt";

  {
  std::ofstream filestr(filename);
  auto starttime = clock();
  for(int i=0; i<numberofdoubles; i++)
    filestr << (double)i << " ";

  auto endtime = clock();
  auto elapsed = (double)(endtime - starttime)/CLOCKS_PER_SEC;
  std::cout << "writing: " << elapsed << std::endl;
  }

  {
  std::ifstream filestr (filename);
  auto starttime = clock();
  for(int i=0; i<numberofdoubles; i++)
    filestr >> x;

  auto endtime = clock();
  auto elapsed = (double)(endtime - starttime)/CLOCKS_PER_SEC;
  std::cout << "reading: " << elapsed << std::endl;
  }

  return 0;
}
相关问题