aboutsummaryrefslogtreecommitdiff
path: root/bench/get-current.cc
blob: e4757674c6c0b3c397b9fbbcaf35584be5cd4a85 (plain)
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
36
37
38
39
40
41
42
#include <benchmark/benchmark.h>

#include <cpuinfo.h>


static void cpuinfo_get_current_processor(benchmark::State& state) {
	cpuinfo_initialize();
	while (state.KeepRunning()) {
		const cpuinfo_processor* current_processor = cpuinfo_get_current_processor();
		benchmark::DoNotOptimize(current_processor);
	}
}
BENCHMARK(cpuinfo_get_current_processor)->Unit(benchmark::kNanosecond);

static void cpuinfo_get_current_core(benchmark::State& state) {
	cpuinfo_initialize();
	while (state.KeepRunning()) {
		const cpuinfo_core* current_core = cpuinfo_get_current_core();
		benchmark::DoNotOptimize(current_core);
	}
}
BENCHMARK(cpuinfo_get_current_core)->Unit(benchmark::kNanosecond);

static void cpuinfo_get_current_uarch_index(benchmark::State& state) {
	cpuinfo_initialize();
	while (state.KeepRunning()) {
		const uint32_t uarch_index = cpuinfo_get_current_uarch_index();
		benchmark::DoNotOptimize(uarch_index);
	}
}
BENCHMARK(cpuinfo_get_current_uarch_index)->Unit(benchmark::kNanosecond);

static void cpuinfo_get_current_uarch_index_with_default(benchmark::State& state) {
	cpuinfo_initialize();
	while (state.KeepRunning()) {
		const uint32_t uarch_index = cpuinfo_get_current_uarch_index_with_default(0);
		benchmark::DoNotOptimize(uarch_index);
	}
}
BENCHMARK(cpuinfo_get_current_uarch_index_with_default)->Unit(benchmark::kNanosecond);

BENCHMARK_MAIN();