diff --git a/benchmarks/src/bitset_to_string.cpp b/benchmarks/src/bitset_to_string.cpp index c5f012c6a18..5fc88147839 100644 --- a/benchmarks/src/bitset_to_string.cpp +++ b/benchmarks/src/bitset_to_string.cpp @@ -13,29 +13,40 @@ using namespace std; namespace { - const auto random_bits = [] { + template + auto random_bits_init() { mt19937_64 rnd{}; - array arr; + array arr; for (auto& d : arr) { d = rnd(); } return arr; - }(); + } + + template + const auto random_bits = random_bits_init(); template void BM_bitset_to_string(benchmark::State& state) { + static_assert(N <= 64); + for (auto _ : state) { - for (const auto& bits : random_bits) { + for (const auto& bits : random_bits<>) { + benchmark::DoNotOptimize(bits); bitset bs{bits}; benchmark::DoNotOptimize(bs.to_string()); } } } - template + template void BM_bitset_to_string_large_single(benchmark::State& state) { - const auto large_bitset = bit_cast>(random_bits); + static_assert(N % 64 == 0 && N >= 64); + const auto& bitset_data = random_bits; + + const auto large_bitset = bit_cast>(bitset_data); for (auto _ : state) { + benchmark::DoNotOptimize(large_bitset); benchmark::DoNotOptimize(large_bitset.to_string()); } } @@ -43,11 +54,11 @@ namespace { BENCHMARK(BM_bitset_to_string<15, char>); BENCHMARK(BM_bitset_to_string<64, char>); -BENCHMARK(BM_bitset_to_string<512, char>); -BENCHMARK(BM_bitset_to_string_large_single); +BENCHMARK(BM_bitset_to_string_large_single<512, char>); +BENCHMARK(BM_bitset_to_string_large_single<2048, char>); BENCHMARK(BM_bitset_to_string<7, wchar_t>); BENCHMARK(BM_bitset_to_string<64, wchar_t>); -BENCHMARK(BM_bitset_to_string<512, wchar_t>); -BENCHMARK(BM_bitset_to_string_large_single); +BENCHMARK(BM_bitset_to_string_large_single<512, wchar_t>); +BENCHMARK(BM_bitset_to_string_large_single<2048, wchar_t>); BENCHMARK_MAIN();