fork download
  1. #include <benchmark/benchmark.h>
  2. #include <vector>
  3. #include <random>
  4.  
  5. using namespace std;
  6.  
  7. static void memoryAccess (benchmark::State &state) {
  8. mt19937 rng(21);
  9. int n = state.range(0);
  10.  
  11. vector<int> data(n);
  12. uniform_int_distribution<int> dist(0, n - 1);
  13. for (int &u : data) u = dist(rng);
  14.  
  15. int index = dist(rng);
  16. for (auto _ : state) {
  17. data[index] = (data[index] == n - 1 ? 0 : data[index] + 1);
  18. benchmark::DoNotOptimize(data[index]);
  19. index = data[index];
  20. }
  21.  
  22. state.SetBytesProcessed(state.iterations() * sizeof(int));
  23. }
  24. BENCHMARK(memoryAccess)->RangeMultiplier(2)->Range(1 << 2, 1 << 22);
  25.  
  26. BENCHMARK_MAIN();
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:10: fatal error: benchmark/benchmark.h: No such file or directory
 #include <benchmark/benchmark.h>
          ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
stdout
Standard output is empty