From df11b0fed040c68ac4fea8837ccbfcd220652e0a Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Fri, 13 Aug 2021 16:40:35 -0700 Subject: [PATCH] keychain: add basic benchmark for privkey derivation --- keychain/bench_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 keychain/bench_test.go diff --git a/keychain/bench_test.go b/keychain/bench_test.go new file mode 100644 index 000000000..5c04eac51 --- /dev/null +++ b/keychain/bench_test.go @@ -0,0 +1,41 @@ +package keychain + +import ( + "testing" + + "github.com/btcsuite/btcd/btcec" + "github.com/stretchr/testify/require" +) + +func BenchmarkDerivePrivKey(t *testing.B) { + cleanUp, wallet, err := createTestBtcWallet( + CoinTypeBitcoin, + ) + if err != nil { + t.Fatalf("unable to create wallet: %v", err) + } + + keyRing := NewBtcWalletKeyRing(wallet, CoinTypeBitcoin) + + defer cleanUp() + + var ( + privKey *btcec.PrivateKey + ) + + keyDesc := KeyDescriptor{ + KeyLocator: KeyLocator{ + Family: KeyFamilyMultiSig, + Index: 1, + }, + } + + t.ReportAllocs() + t.ResetTimer() + + for i := 0; i < t.N; i++ { + privKey, err = keyRing.DerivePrivKey(keyDesc) + } + require.NoError(t, err) + require.NotNil(t, privKey) +}