Skip to content

Commit 66fce18

Browse files
committed
Migrate benchmarks to the JSON State Test format
1 parent 13a7873 commit 66fce18

35 files changed

+31
-212
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "evmc"]
22
path = evmc
33
url = https://github.com/ethereum/evmc
4+
[submodule "test/benchmarks"]
5+
path = test/benchmarks
6+
url = https://github.com/ipsilon/evm-benchmarks

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
cmake_minimum_required(VERSION 3.16...3.23)
66

7-
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/evmc/.git)
7+
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/evmc/.git OR NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/benchmarks/.git)
88
message(FATAL_ERROR "Git submodules not initialized, execute:\n git submodule update --init")
99
endif()
1010

test/bench/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
add_executable(evmone-bench)
66
target_include_directories(evmone-bench PRIVATE ${evmone_private_include_dir})
7-
target_link_libraries(evmone-bench PRIVATE evmone testutils evmc::loader benchmark::benchmark)
7+
target_link_libraries(evmone-bench PRIVATE evmone testutils evmc::loader evmone::statetestutils benchmark::benchmark)
88
target_sources(
99
evmone-bench PRIVATE
1010
bench.cpp

test/bench/bench.cpp

+16-48
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright 2019 The evmone Authors.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#include "../statetest/statetest.hpp"
56
#include "helpers.hpp"
67
#include "synthetic_benchmarks.hpp"
78
#include <benchmark/benchmark.h>
@@ -12,6 +13,7 @@
1213
#include <fstream>
1314
#include <iostream>
1415
#include <span>
16+
#include <string>
1517

1618
namespace fs = std::filesystem;
1719

@@ -48,49 +50,17 @@ struct BenchmarkCase
4850
{}
4951
};
5052

51-
52-
constexpr auto runtime_code_extension = ".bin-runtime";
53-
constexpr auto inputs_extension = ".inputs";
54-
5553
/// Loads the benchmark case's inputs from the inputs file at the given path.
56-
std::vector<BenchmarkCase::Input> load_inputs(const fs::path& path)
54+
std::vector<BenchmarkCase::Input> load_inputs(const StateTransitionTest& state_test)
5755
{
58-
enum class state
59-
{
60-
name,
61-
input,
62-
expected_output
63-
};
64-
65-
auto inputs_file = std::ifstream{path};
66-
6756
std::vector<BenchmarkCase::Input> inputs;
68-
auto st = state::name;
69-
std::string input_name;
70-
bytes input;
71-
for (std::string l; std::getline(inputs_file, l);)
57+
for (size_t i = 0; i < state_test.multi_tx.inputs.size(); ++i)
7258
{
73-
switch (st)
74-
{
75-
case state::name:
76-
if (l.empty())
77-
continue; // Skip any empty line.
78-
input_name = std::move(l);
79-
st = state::input;
80-
break;
81-
82-
case state::input:
83-
input = from_hexx(l);
84-
st = state::expected_output;
85-
break;
86-
87-
case state::expected_output:
88-
inputs.emplace_back(std::move(input_name), std::move(input), from_hexx(l));
89-
input_name = {};
90-
input = {};
91-
st = state::name;
92-
break;
93-
}
59+
const auto input_name = state_test.labels.at(i);
60+
const auto input = state_test.multi_tx.inputs[i];
61+
const bytes expected_output;
62+
63+
inputs.emplace_back(std::move(input_name), std::move(input), std::move(expected_output));
9464
}
9565

9666
return inputs;
@@ -99,16 +69,14 @@ std::vector<BenchmarkCase::Input> load_inputs(const fs::path& path)
9969
/// Loads a benchmark case from a file at `path` and all its inputs from the matching inputs file.
10070
BenchmarkCase load_benchmark(const fs::path& path, const std::string& name_prefix)
10171
{
102-
const auto name = name_prefix + path.stem().string();
72+
auto state_test = evmone::test::load_state_test(path);
10373

104-
std::ifstream file{path};
105-
std::string code_hexx{std::istreambuf_iterator<char>{file}, std::istreambuf_iterator<char>{}};
106-
BenchmarkCase b{name, from_hexx(code_hexx)};
74+
const auto name = name_prefix + path.stem().string();
75+
const auto code = state_test.pre_state.get(state_test.multi_tx.to.value()).code;
76+
const auto inputs = load_inputs(state_test);
10777

108-
auto inputs_path = path;
109-
inputs_path.replace_extension(inputs_extension);
110-
if (fs::exists(inputs_path))
111-
b.inputs = load_inputs(inputs_path);
78+
BenchmarkCase b{name, code};
79+
b.inputs = inputs;
11280

11381
return b;
11482
}
@@ -124,7 +92,7 @@ std::vector<BenchmarkCase> load_benchmarks_from_dir( // NOLINT(misc-no-recursio
12492
{
12593
if (e.is_directory())
12694
subdirs.emplace_back(e);
127-
else if (e.path().extension() == runtime_code_extension)
95+
else if (e.path().extension() == ".json")
12896
code_files.emplace_back(e);
12997
}
13098

test/benchmarks

Submodule benchmarks added at 3a58fc1

test/benchmarks/main/blake2b_huff.bin-runtime

-1
This file was deleted.

test/benchmarks/main/blake2b_huff.inputs

-20
This file was deleted.

test/benchmarks/main/blake2b_shifts.bin-runtime

-1
This file was deleted.

0 commit comments

Comments
 (0)