Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "benchmark/benchmark.h"
- #include <iostream>
- using namespace benchmark;
- int n = 1;
- void func(State &st, int i1) {
- std::cerr << i1 << std::endl;
- for (auto _ : st) {
- for (int i = 0; i < i1; ++i) {
- DoNotOptimize(i);
- }
- }
- }
- BENCHMARK_CAPTURE(func, static_by_reference,
- n); // This works like by reference
- int main(int argc, char **argv) {
- ::benchmark::Initialize(&argc, argv);
- if (::benchmark::ReportUnrecognizedArguments(argc, argv))
- return 1;
- n = 10;
- benchmark::RegisterBenchmark("runtime_by_value", &func,
- n); // this works like by value
- n = 100;
- ::benchmark::RunSpecifiedBenchmarks();
- }
- /*
- OUTPUT:
- 2018-01-11 12:14:54
- Run on (8 X 3500 MHz CPU s)
- CPU Caches:
- L1 Data 32K (x4)
- L1 Instruction 32K (x4)
- L2 Unified 256K (x4)
- L3 Unified 6144K (x1)
- ***WARNING*** CPU scaling is enabled, the benchmark real time measurements may be noisy and will incur extra overhead.
- ***WARNING*** Library was built as DEBUG. Timings may be affected.
- 100
- 100
- 100
- 100
- 100
- 100
- 100
- 100
- ----------------------------------------------------------------
- Benchmark Time CPU Iterations
- ----------------------------------------------------------------
- func/static_by_reference 163 ns 163 ns 3829134
- 10
- 10
- 10
- 10
- 10
- 10
- 10
- 10
- 10
- runtime_by_value
- */
Add Comment
Please, Sign In to add comment