eth.zig

Benchmarks

eth.zig vs alloy.rs -- head-to-head performance comparison across 26 Ethereum operations.

eth.zig vs Rust -- a head-to-head performance comparison of eth.zig and alloy.rs across 26 core Ethereum operations.

Score: eth.zig wins 23/26 | alloy.rs wins 1/26 | tied 2/26

Benchmarks run on Apple Silicon with ReleaseFast (Zig) vs --release (Cargo). Custom criterion-style harness with 0.5s warmup, calibrated batch sizes, and 2s measurement window. Both mulDiv benchmarks use true 512-bit intermediate arithmetic.

Full Results

Benchmarketh.zigalloy.rsWinner
keccak256_empty257 ns334 nszig 1.30x
keccak256_32b259 ns336 nszig 1.30x
keccak256_256b519 ns639 nszig 1.23x
keccak256_1kb2,000 ns2,494 nszig 1.25x
keccak256_4kb7,673 ns9,292 nszig 1.21x
secp256k1_sign24,609 ns51,738 nszig 2.10x
secp256k1_sign_recover54,221 ns218,790 nszig 4.04x
address_derivation262 ns363 nszig 1.39x
address_from_hex15 ns11 nsrs 1.36x
checksum_address307 ns387 nszig 1.26x
abi_encode_transfer25 ns55 nszig 2.20x
abi_encode_static24 ns97 nszig 4.04x
abi_encode_dynamic171 ns324 nszig 1.89x
abi_decode_uint25616 ns50 nszig 3.12x
abi_decode_dynamic32 ns256 nszig 8.00x
rlp_encode_eip1559_tx55 ns72 nszig 1.31x
rlp_decode_u2568 ns9 nszig 1.12x
u256_add4 ns4 nstie
u256_mul4 ns10 nszig 2.50x
u256_div7 ns24 nszig 3.43x
u256_uniswapv2_amount_out21 ns24 nszig 1.14x
u256_mulDiv17 ns29 nszig 1.71x
u256_uniswapv4_swap41 ns45 nszig 1.10x
hex_encode_32b21 ns21 nstie
hex_decode_32b23 ns28 nszig 1.22x
tx_hash_eip1559328 ns402 nszig 1.23x

Score Summary

Count
eth.zig wins23
alloy.rs wins1
Tied2

Key Optimizations

OptimizationImpact
bitcoin-core/secp256k1 C backend (vendored)secp256k1_sign: 2.10x faster than alloy; sign_recover: 4.04x faster
Lane-complementing Keccak-f[1600] (XKCP opt64)keccak256_4kb: 1.21x faster than alloy
Streamlined mulDiv with native u128 divisionmulDiv: 1.71x faster than alloy (17ns vs 29ns)
mulWide + divWide (Knuth D for 512-bit)Replaces 256-iteration binary long division with ~4-iteration Knuth D
U256Limb limb-native arithmeticuniswapv2: beats alloy 1.14x
Half-word division (div128by64)u256_div: 7ns, 3.43x faster than alloy
FixedBufferAllocator in benchmarksEliminates allocator overhead for ABI/RLP/TX benchmarks
Vendored bitcoin-core/secp256k1 + XKCP keccakBest-in-class C backends compiled by zig build
Custom criterion-style harnessAccurate timing in the sub-25ns regime; zbench had ~25ns floor on macOS

Where alloy.rs Wins

BenchmarkGapRoot Cause
address_from_hex1.36xalloy uses SIMD hex parsing; eth.zig uses scalar loop

Reproducing

# Full comparison (requires Zig, Rust, Python 3)
bash bench/compare.sh

# eth.zig benchmarks only
zig build bench

# alloy benchmarks only
(cd bench/alloy-bench && cargo bench --bench eth_comparison)