# EVMMAX Performance Report 1
### Implementations
- native:
- libsecp256k1
- libff
- EVMMAX C++
C++ API directly representing instructions (i.e. addmod, submod and mulmod). Easy for writing precompiles prototypes.
- v1: basic implementation without high-level optimizations
- v2: some high-level optimizations applied to point multiplication: shamir trick, endomorphism
- EVMMAX bytecode v1
The EVMMAX C++ v1 translated to EVM bytecode. This conversion seems to add ~25% runtime overhead
The EVMMAX implementation is done in C/C++ using CIOS montgomery multiplication. This is not optimized. Experiments shows the performance can be increase by at least 10% what speeds up the precompiles by the same rate.
# Results
| impl | ecrecover | bn254_ecadd | bn254_ecmul |
| ------------------ | ---------:| -----------:| -----------:|
| native | 43 µs | 3 µs | 169 µs |
| EVMMAX C++ v2 | 238 µs | 11 µs | **108** µs |
| EVMMAX C++ v1 | 518 µs | 11 µs | 244 µs |
| EVMMAX bytecode v1 | | 14 µs | 343 µs |
# Data
evm precompiles
```
bin/evmone-precompiles-bench --benchmark_repetitions=10 --benchmark_display_aggregates_only=true | grep mean
2024-02-27T19:14:40+01:00
Running bin/evmone-precompiles-bench
Run on (8 X 400 MHz CPU s)
CPU Caches:
L1 Data 32 KiB (x4)
L1 Instruction 32 KiB (x4)
L2 Unified 256 KiB (x4)
L3 Unified 8192 KiB (x1)
Load Average: 0.74, 1.33, 1.44
identity<evmone::state::identity_execute>_mean 35.6 ns 35.6 ns 10 gas_rate=11.2119G/s gas_used=399
ecrecover<evmone::state::ecrecover_execute>_mean 518501 ns 518472 ns 10 gas_rate=5.78628M/s gas_used=3k
ecrecover<evmone::state::silkpre_ecrecover_execute>_mean 43345 ns 43342 ns 10 gas_rate=69.2176M/s gas_used=3k
ecadd<evmone::state::ecadd_execute>_mean 10633 ns 10632 ns 10 gas_rate=14.1079M/s gas_used=150
ecadd<evmone::state::ecadd_evm_execute>_mean 14019 ns 14018 ns 10 gas_rate=10.7004M/s gas_used=150
ecadd<evmone::state::silkpre_ecadd_execute>_mean 3230 ns 3230 ns 10 gas_rate=46.4361M/s gas_used=150
ecmul<evmone::state::ecmul_execute>_mean 244262 ns 244241 ns 10 gas_rate=24.5664M/s gas_used=6k
ecadd<evmone::state::ecmul_evm_execute>_mean 342962 ns 342942 ns 10 gas_rate=437.427k/s gas_used=150
ecmul<evmone::state::silkpre_ecmul_execute>_mean 168872 ns 168852 ns 10 gas_rate=35.5344M/s gas_used=6k
```
with some high level optimizations
```
2024-02-27T19:11:50+01:00
Running bin/evmone-precompiles-bench
Run on (8 X 400 MHz CPU s)
CPU Caches:
L1 Data 32 KiB (x4)
L1 Instruction 32 KiB (x4)
L2 Unified 256 KiB (x4)
L3 Unified 8192 KiB (x1)
Load Average: 0.75, 1.72, 1.56
identity<evmone::state::identity_execute>_mean 35.5 ns 35.5 ns 10 gas_rate=11.2367G/s gas_used=399
ecrecover<evmone::state::ecrecover_execute>_mean 237999 ns 237941 ns 10 gas_rate=12.6087M/s gas_used=3k
ecrecover<evmone::state::silkpre_ecrecover_execute>_mean 43381 ns 43378 ns 10 gas_rate=69.1609M/s gas_used=3k
ecadd<evmone::state::ecadd_execute>_mean 10666 ns 10663 ns 10 gas_rate=14.0677M/s gas_used=150
ecadd<evmone::state::silkpre_ecadd_execute>_mean 3224 ns 3223 ns 10 gas_rate=46.5416M/s gas_used=150
ecmul<evmone::state::ecmul_execute>_mean 103726 ns 103693 ns 10 gas_rate=57.8636M/s gas_used=6k
ecmul<evmone::state::silkpre_ecmul_execute>_mean 169160 ns 169101 ns 10 gas_rate=35.4825M/s gas_used=6k
```
###### tags: `evmmax`