Skip to content

Commit

Permalink
Add benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Jul 15, 2023
1 parent 672abce commit 1884473
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/internal_benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
63 changes: 63 additions & 0 deletions test/internal_benchmarks/evmmax_bench.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2023 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0

#include <benchmark/benchmark.h>
#include <evmmax/evmmax.hpp>

using namespace intx;

namespace
{
constexpr auto bn254 = 0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47_u256;
constexpr auto secp256k1 = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f_u256;

template <typename UintT, const UintT& Mod>
void evmmax_add(benchmark::State& state)
{
const evmmax::ModArith<UintT> 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 <typename UintT, const UintT& Mod>
void evmmax_sub(benchmark::State& state)
{
const evmmax::ModArith<UintT> 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 <typename UintT, const UintT& Mod>
void evmmax_mul(benchmark::State& state)
{
const evmmax::ModArith<UintT> 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);

0 comments on commit 1884473

Please sign in to comment.