fork download
  1. #include <benchmark/benchmark.h>
  2. #include <vector>
  3. #include <random>
  4.  
  5. using namespace std;
  6.  
  7. static void sequentialLoop (benchmark::State& state) {
  8. int n = state.range(0);
  9. vector<int> v(n), ord(n);
  10. iota(ord.begin(), ord.end(), 0);
  11.  
  12. for (auto _ : state) {
  13. for (int i = 0; i < n; i++) v[ord[i]] = ord[i];
  14. benchmark::DoNotOptimize(v.data());
  15. benchmark::ClobberMemory();
  16. }
  17. }
  18. BENCHMARK(sequentialLoop)->RangeMultiplier(2)->Range(1 << 4, 1 << 24);
  19.  
  20. static void randomizedLoop (benchmark::State& state) {
  21. int n = state.range(0);
  22. vector<int> v(n), ord(n);
  23. iota(ord.begin(), ord.end(), 0);
  24. shuffle(ord.begin(), ord.end(), mt19937(21));
  25.  
  26. for (auto _ : state) {
  27. for (int i = 0; i < n; i++) v[ord[i]] = ord[i];
  28. benchmark::DoNotOptimize(v.data());
  29. benchmark::ClobberMemory();
  30. }
  31. }
  32. BENCHMARK(randomizedLoop)->RangeMultiplier(2)->Range(1 << 4, 1 << 24);
  33.  
  34. 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