forked from dendibakh/perf-ninja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.cpp
35 lines (27 loc) · 836 Bytes
/
bench.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "benchmark/benchmark.h"
#include "solution.hpp"
#include <numeric>
#include <thread>
static void bench1(benchmark::State &state) {
const auto size = 1024 * 1024;
std::vector<uint32_t> data;
data.reserve(size);
for (int i = 0; i < size; i++) {
data.push_back(i);
}
// Use thread count from 1 to <number of HW threads>
size_t max_threads = std::thread::hardware_concurrency();
std::vector<int> threads(max_threads);
std::iota(threads.begin(), threads.end(), 1);
for (auto _ : state) {
for (auto thread_count : threads) {
auto result = solution(data, thread_count);
benchmark::DoNotOptimize(result);
}
}
}
// Register the function as a benchmark
BENCHMARK(bench1)->UseRealTime()->Unit(
benchmark::kMillisecond); // ->Iterations(100)
// Run the benchmark
BENCHMARK_MAIN();