Skip to content

Commit

Permalink
txscript: Add benchmark for IsUnspendable.
Browse files Browse the repository at this point in the history
  • Loading branch information
davecgh authored and cfromknecht committed Feb 5, 2021
1 parent eda642a commit 75b614c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
14 changes: 14 additions & 0 deletions txscript/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,17 @@ func BenchmarkIsNullDataScript(b *testing.B) {
_ = IsNullData(script)
}
}

// BenchmarkIsUnspendable benchmarks how long it takes IsUnspendable to analyze
// a very large script.
func BenchmarkIsUnspendable(b *testing.B) {
script, err := genComplexScript()
if err != nil {
b.Fatalf("failed to create benchmark script: %v", err)
}
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = IsUnspendable(script)
}
}
13 changes: 0 additions & 13 deletions txscript/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4334,16 +4334,3 @@ func TestIsUnspendable(t *testing.T) {
}
}
}

// BenchmarkIsUnspendable adds a benchmark to compare the time and allocations
// necessary for the IsUnspendable function.
func BenchmarkIsUnspendable(b *testing.B) {
pkScriptToUse := []byte{0xa9, 0x14, 0x82, 0x1d, 0xba, 0x94, 0xbc, 0xfb, 0xa2, 0x57, 0x36, 0xa3, 0x9e, 0x5d, 0x14, 0x5d, 0x69, 0x75, 0xba, 0x8c, 0x0b, 0x42, 0x87}
var res bool = false
for i := 0; i < b.N; i++ {
res = IsUnspendable(pkScriptToUse)
}
if res {
b.Fatalf("Benchmark should never have res be %t\n", res)
}
}

0 comments on commit 75b614c

Please sign in to comment.