1 #include <benchmark/benchmark.h> 2 3 #include <fxdiv.h> 4 fxdiv_round_down_uint32_t(benchmark::State & state)5static void fxdiv_round_down_uint32_t(benchmark::State& state) { 6 const fxdiv_divisor_uint32_t multiple = fxdiv_init_uint32_t(UINT32_C(65537)); 7 uint32_t x = 0; 8 while (state.KeepRunning()) { 9 const uint32_t rounded_x = fxdiv_round_down_uint32_t(x++, multiple); 10 benchmark::DoNotOptimize(rounded_x); 11 } 12 } 13 BENCHMARK(fxdiv_round_down_uint32_t); 14 fxdiv_round_down_uint64_t(benchmark::State & state)15static void fxdiv_round_down_uint64_t(benchmark::State& state) { 16 const fxdiv_divisor_uint64_t multiple = fxdiv_init_uint64_t(UINT64_C(4294967311)); 17 uint64_t x = 0; 18 while (state.KeepRunning()) { 19 const uint64_t rounded_x = fxdiv_round_down_uint64_t(x++, multiple); 20 benchmark::DoNotOptimize(rounded_x); 21 } 22 } 23 BENCHMARK(fxdiv_round_down_uint64_t); 24 native_round_down_uint32_t(benchmark::State & state)25static void native_round_down_uint32_t(benchmark::State& state) { 26 uint32_t multiple = UINT32_C(65537); 27 benchmark::DoNotOptimize(&multiple); 28 uint32_t x = 0; 29 while (state.KeepRunning()) { 30 const uint32_t rounded_x = x++ / multiple * multiple; 31 benchmark::DoNotOptimize(rounded_x); 32 } 33 } 34 BENCHMARK(native_round_down_uint32_t); 35 native_round_down_uint64_t(benchmark::State & state)36static void native_round_down_uint64_t(benchmark::State& state) { 37 uint64_t multiple = UINT64_C(4294967311); 38 benchmark::DoNotOptimize(&multiple); 39 uint64_t x = 0; 40 while (state.KeepRunning()) { 41 const uint64_t rounded_x = x++ / multiple * multiple; 42 benchmark::DoNotOptimize(rounded_x); 43 } 44 } 45 BENCHMARK(native_round_down_uint64_t); 46 47 BENCHMARK_MAIN(); 48