-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bench: Add evmmax/ModArith benchmarks for uint256
- Loading branch information
Showing
2 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |