-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbench_test.go
88 lines (75 loc) · 2.38 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) 2018-2019 sammyne
// Copyright (c) 2014 The btcsuite developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package bip32_test
import (
"testing"
"github.com/sammyne/bip32"
)
// bip0032MasterPriv1 is the master private extended key from the first set of
// test vectors in BIP0032.
const bip0032MasterPriv1 = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbP" +
"y6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi"
// BenchmarkDeriveHardened benchmarks how long it takes to derive a hardened
// child from a master private extended key.
func BenchmarkDeriveHardened(b *testing.B) {
b.StopTimer()
masterKey, err := bip32.ParsePrivateKey(bip0032MasterPriv1)
if err != nil {
b.Errorf("Failed to decode master seed: %v", err)
}
b.StartTimer()
for i := 0; i < b.N; i++ {
masterKey.Child(bip32.HardenedKeyStart)
}
}
// BenchmarkDeriveNonhardened benchmarks how long it takes to derive a normal
// (non-hardened) child from a master private extended key.
func BenchmarkDeriveNonhardened(b *testing.B) {
b.StopTimer()
//masterKey, err := hdkeychain.NewKeyFromString(bip0032MasterPriv1)
masterKey, err := bip32.ParsePrivateKey(bip0032MasterPriv1)
if err != nil {
b.Errorf("Failed to decode master seed: %v", err)
}
b.StartTimer()
for i := 0; i < b.N; i++ {
masterKey.Child(0)
}
}
// BenchmarkPrivateKey_Public benchmarks how long it takes to convert a private
// extended key to a public extended key.
func BenchmarkPrivateKey_Public(b *testing.B) {
b.StopTimer()
masterKey, err := bip32.ParsePrivateKey(bip0032MasterPriv1)
if err != nil {
b.Errorf("Failed to decode master seed: %v", err)
}
b.StartTimer()
for i := 0; i < b.N; i++ {
masterKey.Neuter()
// invalid the cached public key
masterKey.PublicKey.Data = nil
}
}
// BenchmarkParsePrivateKey benchmarks how long it takes to deserialize a
// private extended key.
func BenchmarkParsePrivateKey(b *testing.B) {
for i := 0; i < b.N; i++ {
bip32.ParsePrivateKey(bip0032MasterPriv1)
}
}
// BenchmarkPrivateKey_String benchmarks how long it takes to serialize a
// private extended key.
func BenchmarkPrivateKey_String(b *testing.B) {
b.StopTimer()
masterKey, err := bip32.ParsePrivateKey(bip0032MasterPriv1)
if err != nil {
b.Errorf("Failed to decode master seed: %v", err)
}
b.StartTimer()
for i := 0; i < b.N; i++ {
_ = masterKey.String()
}
}