|
| 1 | +// evmone: Fast Ethereum Virtual Machine implementation |
| 2 | +// Copyright 2025 The evmone Authors. |
| 3 | +// SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +#include <benchmark/benchmark.h> |
| 6 | +#include <evmone/eof.hpp> |
| 7 | +#include <test/utils/bytecode.hpp> |
| 8 | + |
| 9 | +namespace |
| 10 | +{ |
| 11 | +using namespace evmone::test; |
| 12 | + |
| 13 | +const bytes max_code_sections = [] { |
| 14 | + auto eof_code_sections_1023 = eof_bytecode(jumpf(1)); |
| 15 | + for (int i = 1; i < 1022; ++i) |
| 16 | + eof_code_sections_1023 = |
| 17 | + eof_code_sections_1023.code(jumpf(static_cast<uint16_t>(i + 1)), 0, 0x80, 0); |
| 18 | + |
| 19 | + auto eof_code_sections_1024 = eof_code_sections_1023; |
| 20 | + eof_code_sections_1023 = eof_code_sections_1023.code(OP_STOP, 0, 0x80, 0); |
| 21 | + eof_code_sections_1024 = eof_code_sections_1024.code(jumpf(1023), 0, 0x80, 0); |
| 22 | + eof_code_sections_1024 = eof_code_sections_1024.code(OP_STOP, 0, 0x80, 0); |
| 23 | + return eof_code_sections_1024; |
| 24 | +}(); |
| 25 | + |
| 26 | +void eof_validation(benchmark::State& state, evmone::ContainerKind kind, const bytes& container) |
| 27 | +{ |
| 28 | + for (auto _ : state) |
| 29 | + { |
| 30 | + const auto res = evmone::validate_eof(EVMC_OSAKA, kind, container); |
| 31 | + if (res != evmone::EOFValidationError::success) |
| 32 | + state.SkipWithError(evmone::get_error_message(res).data()); |
| 33 | + } |
| 34 | + |
| 35 | + using namespace benchmark; |
| 36 | + const auto total_size = |
| 37 | + static_cast<double>(state.iterations() * static_cast<IterationCount>(container.size())); |
| 38 | + state.counters["size"] = {static_cast<double>(container.size()), {}, Counter::kIs1024}; |
| 39 | + state.counters["bytes_rate"] = {total_size, Counter::kIsRate, Counter::kIs1024}; |
| 40 | + state.counters["gas_rate"] = {total_size / 16, Counter::kIsRate}; |
| 41 | +} |
| 42 | + |
| 43 | +using enum evmone::ContainerKind; |
| 44 | +BENCHMARK_CAPTURE(eof_validation, max_code_sections, runtime, max_code_sections) |
| 45 | + ->Unit(benchmark::kMicrosecond); |
| 46 | +} // namespace |
0 commit comments