From 4803cc15c7b0939cd84ffbba3a83d439402121bf Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 25 Aug 2021 19:19:33 +0300 Subject: [PATCH] keys: add (*PublicKey).DecodeBytes benchmark MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Attempts to reuse elliptic.Unmarshal() and elliptic.UnmarshalCompressed() lead to this: name old time/op new time/op delta PublicDecodeBytes-8 59.5µs ± 2% 61.8µs ± 1% +3.78% (p=0.000 n=10+9) name old alloc/op new alloc/op delta PublicDecodeBytes-8 3.99kB ± 0% 4.27kB ± 0% +6.81% (p=0.000 n=9+10) name old allocs/op new allocs/op delta PublicDecodeBytes-8 136 ± 0% 135 ± 0% -0.74% (p=0.000 n=10+10) So it makes no sense. Refs. #1319. --- pkg/crypto/keys/publickey_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/crypto/keys/publickey_test.go b/pkg/crypto/keys/publickey_test.go index ce01217e4..13b37ffda 100644 --- a/pkg/crypto/keys/publickey_test.go +++ b/pkg/crypto/keys/publickey_test.go @@ -237,3 +237,12 @@ func BenchmarkPublicUncompressedBytes(t *testing.B) { _ = k.Bytes() } } + +func BenchmarkPublicDecodeBytes(t *testing.B) { + keyBytes, err := hex.DecodeString("03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c") + require.NoError(t, err) + k := new(PublicKey) + for n := 0; n < t.N; n++ { + require.NoError(t, k.DecodeBytes(keyBytes)) + } +}