Skip to content

Commit

Permalink
wire: Add benchmarking for DoubleHashRaw
Browse files Browse the repository at this point in the history
Other benchmarks for DoubleHash are changed to reflect the actual usage
during a TxHash() call.
  • Loading branch information
kcalvinalvin committed Nov 6, 2023
1 parent b975d61 commit dff8559
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions wire/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,31 +604,36 @@ func BenchmarkTxHash(b *testing.B) {
// BenchmarkDoubleHashB performs a benchmark on how long it takes to perform a
// double hash returning a byte slice.
func BenchmarkDoubleHashB(b *testing.B) {
var buf bytes.Buffer
if err := genesisCoinbaseTx.Serialize(&buf); err != nil {
b.Errorf("Serialize: unexpected error: %v", err)
return
}
txBytes := buf.Bytes()

b.ResetTimer()
for i := 0; i < b.N; i++ {
var buf bytes.Buffer
if err := genesisCoinbaseTx.Serialize(&buf); err != nil {
b.Fatalf("Serialize: unexpected error: %v", err)
}
txBytes := buf.Bytes()

_ = chainhash.DoubleHashB(txBytes)
}
}

// BenchmarkDoubleHashH performs a benchmark on how long it takes to perform
// a double hash returning a chainhash.Hash.
func BenchmarkDoubleHashH(b *testing.B) {
var buf bytes.Buffer
if err := genesisCoinbaseTx.Serialize(&buf); err != nil {
b.Errorf("Serialize: unexpected error: %v", err)
return
}
txBytes := buf.Bytes()

b.ResetTimer()
for i := 0; i < b.N; i++ {
var buf bytes.Buffer
if err := genesisCoinbaseTx.Serialize(&buf); err != nil {
b.Fatalf("Serialize: unexpected error: %v", err)
}
txBytes := buf.Bytes()

_ = chainhash.DoubleHashH(txBytes)
}
}

// BenchmarkDoubleHashRaw performs a benchmark on how long it takes to perform
// a double hash returning a byte slice.
func BenchmarkDoubleHashRaw(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = chainhash.DoubleHashRaw(genesisCoinbaseTx.Serialize)
}
}

0 comments on commit dff8559

Please sign in to comment.