#include const std::size_t N = 10'000'000; int si = 0; float sf = 0; struct s1 { int i ; float f ; } data1[N]; struct s2 { int i[N]; float f[N]; } data2 ; struct init { init() { for (std::size_t i = 0; i < N; ++i) data1[i].i = data2.i[i] = data1[i].f = data2.f[i] = i; } } _; template void mixed(benchmark::State &state) { for (auto _ : state) { si = sf = 0; for (std::size_t i = 0; i < N; ++i) { si += data[i].i; sf += data[i].f; } } state.counters.insert({{"si", si}, {"sf", sf}}); } template void indep(benchmark::State &state) { for (auto _ : state) { si = sf = 0; for (std::size_t i = 0; i < N; ++i) si += data[i].i; for (std::size_t i = 0; i < N; ++i) sf += data[i].f; } state.counters.insert({{"si", si}, {"sf", sf}}); } template void mixed(benchmark::State &state) { for (auto _ : state) { si = sf = 0; for (std::size_t i = 0; i < N; ++i) { si += data.i[i]; sf += data.f[i]; } } state.counters.insert({{"si", si}, {"sf", sf}}); } template void indep(benchmark::State &state) { for (auto _ : state) { si = sf = 0; for (std::size_t i = 0; i < N; ++i) si += data.i[i]; for (std::size_t i = 0; i < N; ++i) sf += data.f[i]; } state.counters.insert({{"si", si}, {"sf", sf}}); } BENCHMARK(mixed); BENCHMARK(indep); BENCHMARK(mixed); BENCHMARK(indep); BENCHMARK_MAIN();