diff --git a/test/internal_benchmarks/evmmax_bench.cpp b/test/internal_benchmarks/evmmax_bench.cpp index 7f8f7b31d4..d16529f06d 100644 --- a/test/internal_benchmarks/evmmax_bench.cpp +++ b/test/internal_benchmarks/evmmax_bench.cpp @@ -19,11 +19,14 @@ void evmmax_add(benchmark::State& state) auto a = Mod / 2; auto b = Mod / 3; - while (state.KeepRunningBatch(2)) + for ([[maybe_unused]] auto _ : state) { a = m.add(a, b); b = m.add(b, a); } + state.counters["avg_time_per_item"] = + benchmark::Counter(2.0 * static_cast(state.iterations()), + benchmark::Counter::kIsRate | benchmark::Counter::kInvert); } template @@ -33,11 +36,14 @@ void evmmax_sub(benchmark::State& state) auto a = Mod / 2; auto b = Mod / 3; - while (state.KeepRunningBatch(2)) + for ([[maybe_unused]] auto _ : state) { a = m.sub(a, b); b = m.sub(b, a); } + state.counters["avg_time_per_item"] = + benchmark::Counter(2.0 * static_cast(state.iterations()), + benchmark::Counter::kIsRate | benchmark::Counter::kInvert); } template @@ -47,11 +53,14 @@ void evmmax_mul(benchmark::State& state) auto a = m.to_mont(Mod / 2); auto b = m.to_mont(Mod / 3); - while (state.KeepRunningBatch(2)) + for ([[maybe_unused]] auto _ : state) { a = m.mul(a, b); b = m.mul(b, a); } + state.counters["avg_time_per_item"] = + benchmark::Counter(2.0 * static_cast(state.iterations()), + benchmark::Counter::kIsRate | benchmark::Counter::kInvert); } } // namespace diff --git a/test/internal_benchmarks/find_jumpdest_bench.cpp b/test/internal_benchmarks/find_jumpdest_bench.cpp index 337991145b..377b17c0a2 100644 --- a/test/internal_benchmarks/find_jumpdest_bench.cpp +++ b/test/internal_benchmarks/find_jumpdest_bench.cpp @@ -159,7 +159,7 @@ void find_jumpdest_random(benchmark::State& state) const auto begin = map.data(); benchmark::ClobberMemory(); - while (state.KeepRunningBatch(indexes.size())) + for ([[maybe_unused]] auto _ : state) { for (auto i : indexes) { @@ -167,6 +167,9 @@ void find_jumpdest_random(benchmark::State& state) benchmark::DoNotOptimize(x); } } + state.counters["avg_time_per_item"] = benchmark::Counter( + static_cast(indexes.size()) * static_cast(state.iterations()), + benchmark::Counter::kIsRate | benchmark::Counter::kInvert); } BENCHMARK_TEMPLATE(find_jumpdest_random, int, linear); @@ -269,7 +272,7 @@ void find_jumpdest_split_random(benchmark::State& state) const auto value = map.value.data(); benchmark::ClobberMemory(); - while (state.KeepRunningBatch(indexes.size())) + for ([[maybe_unused]] auto _ : state) { for (auto i : indexes) { @@ -277,6 +280,9 @@ void find_jumpdest_split_random(benchmark::State& state) benchmark::DoNotOptimize(x); } } + state.counters["avg_time_per_item"] = benchmark::Counter( + static_cast(indexes.size()) * static_cast(state.iterations()), + benchmark::Counter::kIsRate | benchmark::Counter::kInvert); } BENCHMARK_TEMPLATE(find_jumpdest_split, uint16_t, lower_bound) ARGS; @@ -294,7 +300,7 @@ void find_jumpdest_hashmap_random(benchmark::State& state) const auto hashmap = std::unordered_map{map.begin(), map.end()}; benchmark::ClobberMemory(); - while (state.KeepRunningBatch(indexes.size())) + for ([[maybe_unused]] auto _ : state) { for (auto i : indexes) { @@ -303,6 +309,9 @@ void find_jumpdest_hashmap_random(benchmark::State& state) benchmark::DoNotOptimize(x); } } + state.counters["avg_time_per_item"] = benchmark::Counter( + static_cast(indexes.size()) * static_cast(state.iterations()), + benchmark::Counter::kIsRate | benchmark::Counter::kInvert); } BENCHMARK_TEMPLATE(find_jumpdest_hashmap_random, int); diff --git a/test/internal_benchmarks/lru_cache_bench.cpp b/test/internal_benchmarks/lru_cache_bench.cpp index 1e332e8bdc..35acda0b7a 100644 --- a/test/internal_benchmarks/lru_cache_bench.cpp +++ b/test/internal_benchmarks/lru_cache_bench.cpp @@ -108,7 +108,7 @@ void lru_cache_put_empty(benchmark::State& state) data[i] = static_cast(i); benchmark::ClobberMemory(); - while (state.KeepRunningBatch(static_cast(capacity))) + for ([[maybe_unused]] auto _ : state) { for (const auto& key : data) { @@ -118,6 +118,9 @@ void lru_cache_put_empty(benchmark::State& state) cache.clear(); state.ResumeTiming(); } + state.counters["avg_time_per_item"] = + benchmark::Counter(static_cast(capacity) * static_cast(state.iterations()), + benchmark::Counter::kIsRate | benchmark::Counter::kInvert); } BENCHMARK(lru_cache_put_empty)->Arg(5000); BENCHMARK(lru_cache_put_empty>)->Arg(5000); diff --git a/test/precompiles_bench/precompiles_bench.cpp b/test/precompiles_bench/precompiles_bench.cpp index 2df05ce2bd..6cd50b75c8 100644 --- a/test/precompiles_bench/precompiles_bench.cpp +++ b/test/precompiles_bench/precompiles_bench.cpp @@ -213,7 +213,7 @@ void precompile(benchmark::State& state) int64_t total_gas_used = 0; - while (state.KeepRunningBatch(inputs.size())) + for ([[maybe_unused]] auto _ : state) { for (const auto& input : inputs) { @@ -228,7 +228,10 @@ void precompile(benchmark::State& state) } using benchmark::Counter; - state.counters["gas_used"] = Counter(static_cast(batch_gas_cost)); + const auto num_inputs = static_cast(inputs.size()); + state.counters["avg_time_per_input"] = Counter( + num_inputs * static_cast(state.iterations()), Counter::kIsRate | Counter::kInvert); + state.counters["avg_gas_used"] = Counter(static_cast(batch_gas_cost) / num_inputs); state.counters["gas_rate"] = Counter(static_cast(total_gas_used), Counter::kIsRate); }