Skip to content

Commit

Permalink
txscript: Add benchmark for CalcWitnessSigHash
Browse files Browse the repository at this point in the history
  • Loading branch information
cfromknecht committed Feb 5, 2021
1 parent c5a193f commit d683492
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions txscript/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}

0 comments on commit d683492

Please sign in to comment.