From a7f404fd1a1a0d4a791a1e29b89935bfe6d662d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 11 May 2021 20:01:12 +0200 Subject: [PATCH] bench: Run execution benchmarks with MockedHost This allows using state-access instructions in benchmarks. Previously such benchmarks would crash. --- test/bench/helpers.hpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/test/bench/helpers.hpp b/test/bench/helpers.hpp index 3dc1ee0554..cc5676b586 100644 --- a/test/bench/helpers.hpp +++ b/test/bench/helpers.hpp @@ -6,6 +6,7 @@ #include "test/utils/utils.hpp" #include #include +#include #include #include @@ -46,14 +47,14 @@ inline void baseline_analyze(benchmark::State& state, bytes_view code) noexcept state.counters["rate"] = Counter(static_cast(bytes_analysed), Counter::kIsRate); } -inline evmc::result execute( - evmc::VM& vm, evmc_revision rev, int64_t gas_limit, bytes_view code, bytes_view input) noexcept +inline evmc::result execute(evmc::VM& vm, evmc::Host& host, evmc_revision rev, int64_t gas_limit, + bytes_view code, bytes_view input) noexcept { auto msg = evmc_message{}; msg.gas = gas_limit; msg.input_data = input.data(); msg.input_size = input.size(); - return vm.execute(rev, msg, code.data(), code.size()); + return vm.execute(host, rev, msg, code.data(), code.size()); } inline void execute(benchmark::State& state, evmc::VM& vm, bytes_view code, bytes_view input = {}, @@ -61,8 +62,11 @@ inline void execute(benchmark::State& state, evmc::VM& vm, bytes_view code, byte { constexpr auto rev = default_revision; constexpr auto gas_limit = default_gas_limit; + + evmc::MockedHost host; + { // Test run. - const auto r = execute(vm, rev, gas_limit, code, input); + const auto r = execute(vm, host, rev, gas_limit, code, input); if (r.status_code != EVMC_SUCCESS) { state.SkipWithError(("failure: " + std::to_string(r.status_code)).c_str()); @@ -85,7 +89,7 @@ inline void execute(benchmark::State& state, evmc::VM& vm, bytes_view code, byte auto iteration_gas_used = int64_t{0}; for (auto _ : state) { - auto r = execute(vm, rev, gas_limit, code, input); + auto r = execute(vm, host, rev, gas_limit, code, input); iteration_gas_used = gas_limit - r.gas_left; total_gas_used += iteration_gas_used; }