Skip to content

Commit 33d9044

Browse files
committed
Migrate benchmarks to the JSON State Test format
1 parent 0897edb commit 33d9044

35 files changed

+59
-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
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ target_sources(
1212
bench.cpp
1313
helpers.hpp
1414
synthetic_benchmarks.cpp synthetic_benchmarks.hpp
15+
${CMAKE_CURRENT_SOURCE_DIR}/../statetest/statetest_loader.cpp
1516
)
1617

1718
# Tests

test/bench/bench.cpp

+15-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>
@@ -47,49 +48,17 @@ struct BenchmarkCase
4748
{}
4849
};
4950

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

9564
return inputs;
@@ -98,16 +67,14 @@ std::vector<BenchmarkCase::Input> load_inputs(const fs::path& path)
9867
/// Loads a benchmark case from a file at `path` and all its inputs from the matching inputs file.
9968
BenchmarkCase load_benchmark(const fs::path& path, const std::string& name_prefix)
10069
{
101-
const auto name = name_prefix + path.stem().string();
70+
auto state_test = evmone::test::load_state_test(path);
10271

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

107-
auto inputs_path = path;
108-
inputs_path.replace_extension(inputs_extension);
109-
if (fs::exists(inputs_path))
110-
b.inputs = load_inputs(inputs_path);
76+
BenchmarkCase b{name, code};
77+
b.inputs = inputs;
11178

11279
return b;
11380
}
@@ -123,7 +90,7 @@ std::vector<BenchmarkCase> load_benchmarks_from_dir( // NOLINT(misc-no-recursio
12390
{
12491
if (e.is_directory())
12592
subdirs.emplace_back(e);
126-
else if (e.path().extension() == runtime_code_extension)
93+
else if (e.path().extension() == ".json")
12794
code_files.emplace_back(e);
12895
}
12996

test/benchmarks

Submodule benchmarks added at 849b3e2

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.

test/benchmarks/main/blake2b_shifts.inputs

-16
This file was deleted.

0 commit comments

Comments
 (0)