0

我的 .h 文件中有这段代码:

std::mt19937 rng(time(NULL)); // mersenne numbers
int random(int n) {
  std::uniform_int_distribution<int> distribution(0, n);
  return distribution(rng);
}

但我从不打电话random()

当我使用 gprof 分析代码时,我得到:

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls   s/call   s/call  name    
 99.13      2.28     2.28        1     2.28     2.28  random(int)

怎么了?

4

1 回答 1

1

如果您使用 -O3 编译器会积极内联所有内容,因此如果 rng 可以随机使用某些代码,它可能会混淆 rng 和 random 的代码。使用 -O0 重试

于 2014-09-12T16:10:24.770 回答