forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
address_bench_test.go
49 lines (36 loc) · 989 Bytes
/
address_bench_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package types_test
import (
"math/rand"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/tendermint/crypto/ed25519"
)
func BenchmarkBech32ifyPubKey(b *testing.B) {
var pk ed25519.PubKeyEd25519
rng := rand.New(rand.NewSource(time.Now().Unix()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
rng.Read(pk[:])
b.StartTimer()
_, err := types.Bech32ifyPubKey(types.Bech32PubKeyTypeConsPub, pk)
require.NoError(b, err)
}
}
func BenchmarkGetPubKeyFromBech32(b *testing.B) {
var pk ed25519.PubKeyEd25519
rng := rand.New(rand.NewSource(time.Now().Unix()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
rng.Read(pk[:])
pkStr, err := types.Bech32ifyPubKey(types.Bech32PubKeyTypeConsPub, pk)
require.NoError(b, err)
b.StartTimer()
pk2, err := types.GetPubKeyFromBech32(types.Bech32PubKeyTypeConsPub, pkStr)
require.NoError(b, err)
require.Equal(b, pk, pk2)
}
}