Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bench: Run execution benchmarks with MockedHost #319

Merged
merged 1 commit into from
May 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions test/bench/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "test/utils/utils.hpp"
#include <benchmark/benchmark.h>
#include <evmc/evmc.hpp>
#include <evmc/mocked_host.hpp>
#include <evmone/analysis.hpp>
#include <evmone/baseline.hpp>

Expand Down Expand Up @@ -46,23 +47,26 @@ inline void baseline_analyze(benchmark::State& state, bytes_view code) noexcept
state.counters["rate"] = Counter(static_cast<double>(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 = {},
bytes_view expected_output = {}) noexcept
{
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());
Expand All @@ -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;
}
Expand Down