Skip to content

Commit a98fff2

Browse files
committed
bench: Add benchmarks for EOF validation
Run: ```sh evmone-bench-internal --benchmark_counters_tabular=true --benchmark_filter=eof_validation ```
1 parent 9d28979 commit a98fff2

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

Diff for: test/internal_benchmarks/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
add_executable(
66
evmone-bench-internal
7+
eof_validation_bench.cpp
78
evmmax_bench.cpp
89
find_jumpdest_bench.cpp
910
memory_allocation.cpp
1011
)
1112

12-
target_link_libraries(evmone-bench-internal PRIVATE evmone::evmmax benchmark::benchmark)
13+
target_link_libraries(evmone-bench-internal PRIVATE evmone evmone::evmmax evmone::testutils benchmark::benchmark)
14+
target_include_directories(evmone-bench-internal PRIVATE ${evmone_private_include_dir})

Diff for: test/internal_benchmarks/eof_validation_bench.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

Comments
 (0)