txscript: Add benchmark for IsUnspendable.

This commit is contained in:
Dave Collins 2019-03-13 01:12:20 -05:00 committed by Olaoluwa Osuntokun
parent 5f771c1aaa
commit 77660b7fb0
No known key found for this signature in database
GPG key ID: 3BBD59E99B280306
2 changed files with 14 additions and 13 deletions

View file

@ -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)
}
}

View file

@ -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)
}
}