btcec: benchmark ParsePubKey for compressed keys

This commit is contained in:
Conner Fromknecht 2019-05-14 22:46:50 -07:00
parent 962a206e94
commit 4aeb189fc4
No known key found for this signature in database
GPG key ID: E7D737B67FA592C7

View file

@ -4,7 +4,10 @@
package btcec package btcec
import "testing" import (
"encoding/hex"
"testing"
)
// BenchmarkAddJacobian benchmarks the secp256k1 curve addJacobian function with // BenchmarkAddJacobian benchmarks the secp256k1 curve addJacobian function with
// Z values of 1 so that the associated optimizations are used. // Z values of 1 so that the associated optimizations are used.
@ -121,3 +124,22 @@ func BenchmarkFieldNormalize(b *testing.B) {
f.Normalize() f.Normalize()
} }
} }
// BenchmarkParseCompressedPubKey benchmarks how long it takes to decompress and
// validate a compressed public key from a byte array.
func BenchmarkParseCompressedPubKey(b *testing.B) {
rawPk, _ := hex.DecodeString("0234f9460f0e4f08393d192b3c5133a6ba099aa0ad9fd54ebccfacdfa239ff49c6")
var (
pk *PublicKey
err error
)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
pk, err = ParsePubKey(rawPk, S256())
}
_ = pk
_ = err
}