1
+ // Copyright (c) 2018-2019 sammyne
1
2
// Copyright (c) 2014 The btcsuite developers
2
3
// Use of this source code is governed by an ISC
3
4
// license that can be found in the LICENSE file.
4
5
5
6
package bip32_test
6
7
7
- /*
8
8
import (
9
9
"testing"
10
10
11
- "github.com/btcsuite/btcutil/hdkeychain "
11
+ "github.com/sammyne/bip32 "
12
12
)
13
13
14
14
// bip0032MasterPriv1 is the master private extended key from the first set of
@@ -20,22 +20,23 @@ const bip0032MasterPriv1 = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbP" +
20
20
// child from a master private extended key.
21
21
func BenchmarkDeriveHardened (b * testing.B ) {
22
22
b .StopTimer ()
23
- masterKey, err := hdkeychain.NewKeyFromString (bip0032MasterPriv1)
23
+ masterKey , err := bip32 . ParsePrivateKey (bip0032MasterPriv1 )
24
24
if err != nil {
25
25
b .Errorf ("Failed to decode master seed: %v" , err )
26
26
}
27
27
b .StartTimer ()
28
28
29
29
for i := 0 ; i < b .N ; i ++ {
30
- masterKey.Child(hdkeychain .HardenedKeyStart)
30
+ masterKey .Child (bip32 .HardenedKeyStart )
31
31
}
32
32
}
33
33
34
- // BenchmarkDeriveNormal benchmarks how long it takes to derive a normal
34
+ // BenchmarkDeriveNonhardened benchmarks how long it takes to derive a normal
35
35
// (non-hardened) child from a master private extended key.
36
- func BenchmarkDeriveNormal (b *testing.B) {
36
+ func BenchmarkDeriveNonhardened (b * testing.B ) {
37
37
b .StopTimer ()
38
- masterKey, err := hdkeychain.NewKeyFromString(bip0032MasterPriv1)
38
+ //masterKey, err := hdkeychain.NewKeyFromString(bip0032MasterPriv1)
39
+ masterKey , err := bip32 .ParsePrivateKey (bip0032MasterPriv1 )
39
40
if err != nil {
40
41
b .Errorf ("Failed to decode master seed: %v" , err )
41
42
}
@@ -46,34 +47,36 @@ func BenchmarkDeriveNormal(b *testing.B) {
46
47
}
47
48
}
48
49
49
- // BenchmarkPrivToPub benchmarks how long it takes to convert a private extended
50
- // key to a public extended key.
51
- func BenchmarkPrivToPub (b *testing.B) {
50
+ // BenchmarkPrivateKey_Public benchmarks how long it takes to convert a private
51
+ // extended key to a public extended key.
52
+ func BenchmarkPrivateKey_Public (b * testing.B ) {
52
53
b .StopTimer ()
53
- masterKey, err := hdkeychain.NewKeyFromString (bip0032MasterPriv1)
54
+ masterKey , err := bip32 . ParsePrivateKey (bip0032MasterPriv1 )
54
55
if err != nil {
55
56
b .Errorf ("Failed to decode master seed: %v" , err )
56
57
}
57
58
b .StartTimer ()
58
59
59
60
for i := 0 ; i < b .N ; i ++ {
60
61
masterKey .Neuter ()
62
+ // invalid the cached public key
63
+ masterKey .PublicKey .Data = nil
61
64
}
62
65
}
63
66
64
- // BenchmarkDeserialize benchmarks how long it takes to deserialize a private
65
- // extended key.
66
- func BenchmarkDeserialize (b *testing.B) {
67
+ // BenchmarkParsePrivateKey benchmarks how long it takes to deserialize a
68
+ // private extended key.
69
+ func BenchmarkParsePrivateKey (b * testing.B ) {
67
70
for i := 0 ; i < b .N ; i ++ {
68
- hdkeychain.NewKeyFromString (bip0032MasterPriv1)
71
+ bip32 . ParsePrivateKey (bip0032MasterPriv1 )
69
72
}
70
73
}
71
74
72
- // BenchmarkSerialize benchmarks how long it takes to serialize a private
73
- // extended key.
74
- func BenchmarkSerialize (b *testing.B) {
75
+ // BenchmarkPrivateKey_String benchmarks how long it takes to serialize a
76
+ // private extended key.
77
+ func BenchmarkPrivateKey_String (b * testing.B ) {
75
78
b .StopTimer ()
76
- masterKey, err := hdkeychain.NewKeyFromString (bip0032MasterPriv1)
79
+ masterKey , err := bip32 . ParsePrivateKey (bip0032MasterPriv1 )
77
80
if err != nil {
78
81
b .Errorf ("Failed to decode master seed: %v" , err )
79
82
}
@@ -83,4 +86,3 @@ func BenchmarkSerialize(b *testing.B) {
83
86
_ = masterKey .String ()
84
87
}
85
88
}
86
- */
0 commit comments