Skip to content

Commit df7e02b

Browse files
authored
Merge pull request #319 from ethereum/bench_mocked_host
bench: Run execution benchmarks with MockedHost
2 parents 4a7161b + a7f404f commit df7e02b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

test/bench/helpers.hpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "test/utils/utils.hpp"
77
#include <benchmark/benchmark.h>
88
#include <evmc/evmc.hpp>
9+
#include <evmc/mocked_host.hpp>
910
#include <evmone/analysis.hpp>
1011
#include <evmone/baseline.hpp>
1112

@@ -46,23 +47,26 @@ inline void baseline_analyze(benchmark::State& state, bytes_view code) noexcept
4647
state.counters["rate"] = Counter(static_cast<double>(bytes_analysed), Counter::kIsRate);
4748
}
4849

49-
inline evmc::result execute(
50-
evmc::VM& vm, evmc_revision rev, int64_t gas_limit, bytes_view code, bytes_view input) noexcept
50+
inline evmc::result execute(evmc::VM& vm, evmc::Host& host, evmc_revision rev, int64_t gas_limit,
51+
bytes_view code, bytes_view input) noexcept
5152
{
5253
auto msg = evmc_message{};
5354
msg.gas = gas_limit;
5455
msg.input_data = input.data();
5556
msg.input_size = input.size();
56-
return vm.execute(rev, msg, code.data(), code.size());
57+
return vm.execute(host, rev, msg, code.data(), code.size());
5758
}
5859

5960
inline void execute(benchmark::State& state, evmc::VM& vm, bytes_view code, bytes_view input = {},
6061
bytes_view expected_output = {}) noexcept
6162
{
6263
constexpr auto rev = default_revision;
6364
constexpr auto gas_limit = default_gas_limit;
65+
66+
evmc::MockedHost host;
67+
6468
{ // Test run.
65-
const auto r = execute(vm, rev, gas_limit, code, input);
69+
const auto r = execute(vm, host, rev, gas_limit, code, input);
6670
if (r.status_code != EVMC_SUCCESS)
6771
{
6872
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
8589
auto iteration_gas_used = int64_t{0};
8690
for (auto _ : state)
8791
{
88-
auto r = execute(vm, rev, gas_limit, code, input);
92+
auto r = execute(vm, host, rev, gas_limit, code, input);
8993
iteration_gas_used = gas_limit - r.gas_left;
9094
total_gas_used += iteration_gas_used;
9195
}

0 commit comments

Comments
 (0)