ITADN

`if` should be `while` in `if (volume * repeat < 10000000)`?

#103Closedmaksverver 创建于 2024-08-23
M
maksververcommented
[This code](https://github.com/lemire/Code-used-on-Daniel-Lemire-s-blog/blob/5a67b83126ad98980736e3dba3a650d73de9f162/2024/08/16/benchmarks/stream.cpp#L51C1-L53C4): ```c++ if (volume * repeat < 10000000) { repeat++; } ``` looks dubious. Probably it was meant to be *while* instead of *if*? But since *repeat* is initialized to 1, it's probably better to eliminate the loop entirely, and simply write: ```c++ size_t repeat = 9'999'999 / volume + 1; ``` (As an aside, the entire benchmark framework seems more complex than it needs to be. It's more common for the framework to pass the number of iterations to the function executing, instead of having repetitions both inside the benchmark framework and in the code being benchmarked. Take a look at some existing microbenchmark frameworks like Google Benchmark or Ankerl nanobench for inspiration.)
关闭于 2024-08-23 1 条评论