小编Fre*_*ers的帖子

添加打印语句可将代码加速一个数量级

我在一篇C/C++代码中遇到了一个非常奇怪的性能行为,如标题中所示,我不知道如何解释.

这是一个尽可能接近最小的工作示例[编辑:见下面的较短的一个]:

#include <stdio.h>
#include <stdlib.h>
#include <complex>

using namespace std;

const int pp = 29;
typedef complex<double> cdbl;

int main() {
  cdbl ff[pp], gg[pp];
  for(int ii = 0; ii < pp; ii++) {
    ff[ii] = gg[ii] = 1.0;
  }

  for(int it = 0; it < 1000; it++) {
    cdbl dual[pp];

    for(int ii = 0; ii < pp; ii++) {
      dual[ii] = 0.0;
    }

    for(int h1 = 0; h1 < pp; h1 ++) {
      for(int h2 = 0; h2 < …
Run Code Online (Sandbox Code Playgroud)

c++ performance

8
推荐指数
1
解决办法
349
查看次数

标签 统计

c++ ×1

performance ×1