• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <benchmark/benchmark.h>
2 
3 #include <fxdiv.h>
4 
fxdiv_quotient_uint32_t(benchmark::State & state)5 static void fxdiv_quotient_uint32_t(benchmark::State& state) {
6 	const fxdiv_divisor_uint32_t divisor = fxdiv_init_uint32_t(UINT32_C(65537));
7 	uint32_t x = 0;
8 	while (state.KeepRunning()) {
9 		uint32_t quotient = fxdiv_quotient_uint32_t(x++, divisor);
10 		benchmark::DoNotOptimize(quotient);
11 	}
12 }
13 BENCHMARK(fxdiv_quotient_uint32_t);
14 
fxdiv_quotient_uint64_t(benchmark::State & state)15 static void fxdiv_quotient_uint64_t(benchmark::State& state) {
16 	const fxdiv_divisor_uint64_t divisor = fxdiv_init_uint64_t(UINT64_C(4294967311));
17 	uint64_t x = 0;
18 	while (state.KeepRunning()) {
19 		uint64_t quotient = fxdiv_quotient_uint64_t(x++, divisor);
20 		benchmark::DoNotOptimize(quotient);
21 	}
22 }
23 BENCHMARK(fxdiv_quotient_uint64_t);
24 
native_quotient_uint32_t(benchmark::State & state)25 static void native_quotient_uint32_t(benchmark::State& state) {
26 	uint32_t divisor = UINT32_C(65537);
27 	benchmark::DoNotOptimize(&divisor);
28 	uint32_t x = UINT32_MAX;
29 	while (state.KeepRunning()) {
30 		uint32_t quotient = x-- / divisor;
31 		benchmark::DoNotOptimize(quotient);
32 	}
33 }
34 BENCHMARK(native_quotient_uint32_t);
35 
native_quotient_uint64_t(benchmark::State & state)36 static void native_quotient_uint64_t(benchmark::State& state) {
37 	uint64_t divisor = UINT64_C(4294967311);
38     benchmark::DoNotOptimize(&divisor);
39 	uint64_t x = UINT64_MAX;
40 	while (state.KeepRunning()) {
41 		const uint64_t quotient = x-- / divisor;
42 		benchmark::DoNotOptimize(quotient);
43 	}
44 }
45 BENCHMARK(native_quotient_uint64_t);
46 
47 BENCHMARK_MAIN();
48