Skip to content

Commit

Permalink
bench: Add benchmarks for EOF validation
Browse files Browse the repository at this point in the history
Run:

```sh
evmone-bench-internal --benchmark_counters_tabular=true --benchmark_filter=eof_validation
```
  • Loading branch information
chfast committed Jan 29, 2025
1 parent 9d28979 commit a98fff2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
4 changes: 3 additions & 1 deletion test/internal_benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

add_executable(
evmone-bench-internal
eof_validation_bench.cpp
evmmax_bench.cpp
find_jumpdest_bench.cpp
memory_allocation.cpp
)

target_link_libraries(evmone-bench-internal PRIVATE evmone::evmmax benchmark::benchmark)
target_link_libraries(evmone-bench-internal PRIVATE evmone evmone::evmmax evmone::testutils benchmark::benchmark)
target_include_directories(evmone-bench-internal PRIVATE ${evmone_private_include_dir})
46 changes: 46 additions & 0 deletions test/internal_benchmarks/eof_validation_bench.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2025 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0

#include <benchmark/benchmark.h>
#include <evmone/eof.hpp>
#include <test/utils/bytecode.hpp>

namespace
{
using namespace evmone::test;

const bytes max_code_sections = [] {
auto eof_code_sections_1023 = eof_bytecode(jumpf(1));
for (int i = 1; i < 1022; ++i)

Check warning on line 15 in test/internal_benchmarks/eof_validation_bench.cpp

View check run for this annotation

Codecov / codecov/patch

test/internal_benchmarks/eof_validation_bench.cpp#L13-L15

Added lines #L13 - L15 were not covered by tests
eof_code_sections_1023 =
eof_code_sections_1023.code(jumpf(static_cast<uint16_t>(i + 1)), 0, 0x80, 0);

Check warning on line 17 in test/internal_benchmarks/eof_validation_bench.cpp

View check run for this annotation

Codecov / codecov/patch

test/internal_benchmarks/eof_validation_bench.cpp#L17

Added line #L17 was not covered by tests

auto eof_code_sections_1024 = eof_code_sections_1023;
eof_code_sections_1023 = eof_code_sections_1023.code(OP_STOP, 0, 0x80, 0);
eof_code_sections_1024 = eof_code_sections_1024.code(jumpf(1023), 0, 0x80, 0);
eof_code_sections_1024 = eof_code_sections_1024.code(OP_STOP, 0, 0x80, 0);
return eof_code_sections_1024;
}();

Check warning on line 24 in test/internal_benchmarks/eof_validation_bench.cpp

View check run for this annotation

Codecov / codecov/patch

test/internal_benchmarks/eof_validation_bench.cpp#L19-L24

Added lines #L19 - L24 were not covered by tests

void eof_validation(benchmark::State& state, evmone::ContainerKind kind, const bytes& container)

Check warning on line 26 in test/internal_benchmarks/eof_validation_bench.cpp

View check run for this annotation

Codecov / codecov/patch

test/internal_benchmarks/eof_validation_bench.cpp#L26

Added line #L26 was not covered by tests
{
for (auto _ : state)

Check warning on line 28 in test/internal_benchmarks/eof_validation_bench.cpp

View check run for this annotation

Codecov / codecov/patch

test/internal_benchmarks/eof_validation_bench.cpp#L28

Added line #L28 was not covered by tests
{
const auto res = evmone::validate_eof(EVMC_OSAKA, kind, container);
if (res != evmone::EOFValidationError::success)
state.SkipWithError(evmone::get_error_message(res).data());

Check warning on line 32 in test/internal_benchmarks/eof_validation_bench.cpp

View check run for this annotation

Codecov / codecov/patch

test/internal_benchmarks/eof_validation_bench.cpp#L30-L32

Added lines #L30 - L32 were not covered by tests
}

using namespace benchmark;
const auto total_size =
static_cast<double>(state.iterations() * static_cast<IterationCount>(container.size()));
state.counters["size"] = {static_cast<double>(container.size()), {}, Counter::kIs1024};
state.counters["bytes_rate"] = {total_size, Counter::kIsRate, Counter::kIs1024};
state.counters["gas_rate"] = {total_size / 16, Counter::kIsRate};
}

Check warning on line 41 in test/internal_benchmarks/eof_validation_bench.cpp

View check run for this annotation

Codecov / codecov/patch

test/internal_benchmarks/eof_validation_bench.cpp#L37-L41

Added lines #L37 - L41 were not covered by tests

using enum evmone::ContainerKind;
BENCHMARK_CAPTURE(eof_validation, max_code_sections, runtime, max_code_sections)

Check warning on line 44 in test/internal_benchmarks/eof_validation_bench.cpp

View check run for this annotation

Codecov / codecov/patch

test/internal_benchmarks/eof_validation_bench.cpp#L44

Added line #L44 was not covered by tests
->Unit(benchmark::kMicrosecond);
} // namespace

0 comments on commit a98fff2

Please sign in to comment.