From d683492b002511bd068600dae29a6e57d58c7194 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 4 Feb 2021 23:45:31 -0800 Subject: [PATCH] txscript: Add benchmark for CalcWitnessSigHash --- txscript/bench_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/txscript/bench_test.go b/txscript/bench_test.go index b129b80386..037ce531f7 100644 --- a/txscript/bench_test.go +++ b/txscript/bench_test.go @@ -50,3 +50,23 @@ func BenchmarkCalcSigHash(b *testing.B) { } } } + +// BenchmarkCalcWitnessSigHash benchmarks how long it takes to calculate the +// witness signature hashes for all inputs of a transaction with many inputs. +func BenchmarkCalcWitnessSigHash(b *testing.B) { + sigHashes := NewTxSigHashes(&manyInputsBenchTx) + + b.ResetTimer() + b.ReportAllocs() + for i := 0; i < b.N; i++ { + for j := 0; j < len(manyInputsBenchTx.TxIn); j++ { + _, err := CalcWitnessSigHash( + prevOutScript, sigHashes, SigHashAll, + &manyInputsBenchTx, j, 5, + ) + if err != nil { + b.Fatalf("failed to calc signature hash: %v", err) + } + } + } +}