This benchmark suite compares three different secp256k1 implementations:
# Install btcec
go get github.com/btcsuite/btcd/btcec/v2
go get github.com/decred/dcrd/dcrec/secp256k1/v4
# Install p256k1 (if not already available)
go get github.com/mleku/p256k1
# Install libsecp256k1 (for p8k benchmarks)
# Ubuntu/Debian:
sudo apt-get install libsecp256k1-dev
# macOS:
brew install libsecp256k1
# Or build from source:
cd ..
make install-secp256k1
cd bench
go test -bench=BenchmarkAll -benchmem -benchtime=10s
# Public key derivation comparison
go test -bench=BenchmarkComparative_PubkeyDerivation -benchmem -benchtime=10s
# Schnorr signing comparison
go test -bench=BenchmarkComparative_SchnorrSign -benchmem -benchtime=10s
# Schnorr verification comparison
go test -bench=BenchmarkComparative_SchnorrVerify -benchmem -benchtime=10s
# ECDH comparison
go test -bench=BenchmarkComparative_ECDH -benchmem -benchtime=10s
# Only BTCEC
go test -bench=BenchmarkBTCEC -benchmem
# Only P256K1
go test -bench=BenchmarkP256K1 -benchmem
# Only P8K
go test -bench=BenchmarkP8K -benchmem
# Run and save results
go test -bench=BenchmarkAll -benchmem -benchtime=10s | tee results.txt
# Or use benchstat for statistical analysis
go install golang.org/x/perf/cmd/benchstat@latest
# Run multiple times for better statistical analysis
go test -bench=BenchmarkAll -benchmem -benchtime=10s -count=10 | tee results.txt
benchstat results.txt
The benchmarks will show:
BTCEC:
P256K1:
P8K (this package):
Example output:
BenchmarkAll/PubkeyDerivation/BTCEC-8 100000 10234 ns/op 128 B/op 2 allocs/op
BenchmarkAll/PubkeyDerivation/P256K1-8 80000 12456 ns/op 192 B/op 4 allocs/op
BenchmarkAll/PubkeyDerivation/P8K-8 120000 8765 ns/op 64 B/op 1 allocs/op
All benchmarks use:
- If not available, P8K Schnorr benchmarks will be skipped
- Install with: ./configure --enable-module-schnorrsig when building from source
- If not available, P8K ECDH benchmarks will be skipped
- Install with: ./configure --enable-module-ecdh when building from source
-benchtime flag-count flag for multiple runs to get better statistical dataNote: Even if some P8K benchmarks are skipped, the comparison between BTCEC and P256K1 will still provide valuable performance data.
When choosing an implementation, consider:
To add more benchmarks or implementations: