From 6789e2e8098140db4cad768a8646ad230fb58a13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Sat, 15 Jul 2023 22:50:23 +0200 Subject: [PATCH] Add benchmarks --- test/internal_benchmarks/CMakeLists.txt | 3 +- test/internal_benchmarks/evmmax_bench.cpp | 63 +++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 test/internal_benchmarks/evmmax_bench.cpp diff --git a/test/internal_benchmarks/CMakeLists.txt b/test/internal_benchmarks/CMakeLists.txt index 2a5a4902d1..4b5228d687 100644 --- a/test/internal_benchmarks/CMakeLists.txt +++ b/test/internal_benchmarks/CMakeLists.txt @@ -4,8 +4,9 @@ add_executable( evmone-bench-internal + evmmax_bench.cpp find_jumpdest_bench.cpp memory_allocation.cpp ) -target_link_libraries(evmone-bench-internal PRIVATE benchmark::benchmark) +target_link_libraries(evmone-bench-internal PRIVATE evmone::evmmax benchmark::benchmark) diff --git a/test/internal_benchmarks/evmmax_bench.cpp b/test/internal_benchmarks/evmmax_bench.cpp new file mode 100644 index 0000000000..7f8f7b31d4 --- /dev/null +++ b/test/internal_benchmarks/evmmax_bench.cpp @@ -0,0 +1,63 @@ +// evmone: Fast Ethereum Virtual Machine implementation +// Copyright 2023 The evmone Authors. +// SPDX-License-Identifier: Apache-2.0 + +#include +#include + +using namespace intx; + +namespace +{ +constexpr auto bn254 = 0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47_u256; +constexpr auto secp256k1 = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f_u256; + +template +void evmmax_add(benchmark::State& state) +{ + const evmmax::ModArith m{Mod}; + auto a = Mod / 2; + auto b = Mod / 3; + + while (state.KeepRunningBatch(2)) + { + a = m.add(a, b); + b = m.add(b, a); + } +} + +template +void evmmax_sub(benchmark::State& state) +{ + const evmmax::ModArith m{Mod}; + auto a = Mod / 2; + auto b = Mod / 3; + + while (state.KeepRunningBatch(2)) + { + a = m.sub(a, b); + b = m.sub(b, a); + } +} + +template +void evmmax_mul(benchmark::State& state) +{ + const evmmax::ModArith m{Mod}; + auto a = m.to_mont(Mod / 2); + auto b = m.to_mont(Mod / 3); + + while (state.KeepRunningBatch(2)) + { + a = m.mul(a, b); + b = m.mul(b, a); + } +} +} // namespace + +BENCHMARK_TEMPLATE(evmmax_add, uint256, bn254); +BENCHMARK_TEMPLATE(evmmax_add, uint256, secp256k1); +BENCHMARK_TEMPLATE(evmmax_sub, uint256, bn254); +BENCHMARK_TEMPLATE(evmmax_sub, uint256, secp256k1); +BENCHMARK_TEMPLATE(evmmax_mul, uint256, bn254); +BENCHMARK_TEMPLATE(evmmax_mul, uint256, secp256k1);