Guest User

Untitled

a guest
Jan 20th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include "benchmark/benchmark.h"
  2. #include <iostream>
  3.  
  4. using namespace benchmark;
  5.  
  6. int n = 1;
  7.  
  8. void func(State &st, int i1) {
  9. std::cerr << i1 << std::endl;
  10. for (auto _ : st) {
  11. for (int i = 0; i < i1; ++i) {
  12. DoNotOptimize(i);
  13. }
  14. }
  15. }
  16.  
  17. BENCHMARK_CAPTURE(func, static_by_reference,
  18. n); // This works like by reference
  19.  
  20. int main(int argc, char **argv) {
  21. ::benchmark::Initialize(&argc, argv);
  22. if (::benchmark::ReportUnrecognizedArguments(argc, argv))
  23. return 1;
  24. n = 10;
  25. benchmark::RegisterBenchmark("runtime_by_value", &func,
  26. n); // this works like by value
  27. n = 100;
  28. ::benchmark::RunSpecifiedBenchmarks();
  29. }
  30. /*
  31. OUTPUT:
  32. 2018-01-11 12:14:54
  33. Run on (8 X 3500 MHz CPU s)
  34. CPU Caches:
  35. L1 Data 32K (x4)
  36. L1 Instruction 32K (x4)
  37. L2 Unified 256K (x4)
  38. L3 Unified 6144K (x1)
  39. ***WARNING*** CPU scaling is enabled, the benchmark real time measurements may be noisy and will incur extra overhead.
  40. ***WARNING*** Library was built as DEBUG. Timings may be affected.
  41. 100
  42. 100
  43. 100
  44. 100
  45. 100
  46. 100
  47. 100
  48. 100
  49. ----------------------------------------------------------------
  50. Benchmark Time CPU Iterations
  51. ----------------------------------------------------------------
  52. func/static_by_reference 163 ns 163 ns 3829134
  53. 10
  54. 10
  55. 10
  56. 10
  57. 10
  58. 10
  59. 10
  60. 10
  61. 10
  62. runtime_by_value
  63. */
Add Comment
Please, Sign In to add comment