txscript: Add benchmark for IsNullData

This commit is contained in:
Dave Collins 2019-03-13 01:11:49 -05:00 committed by Olaoluwa Osuntokun
parent 55a6bb5e32
commit e4118c914f
No known key found for this signature in database
GPG key ID: 3BBD59E99B280306
2 changed files with 25 additions and 0 deletions

View file

@ -312,3 +312,18 @@ func BenchmarkIsWitnessScriptHash(b *testing.B) {
_ = IsPayToWitnessScriptHash(script) _ = IsPayToWitnessScriptHash(script)
} }
} }
// BenchmarkIsNullDataScript benchmarks how long it takes to analyze a very
// large script to determine if it is a standard nulldata script.
func BenchmarkIsNullDataScript(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++ {
_ = IsNullData(script)
}
}

View file

@ -151,6 +151,16 @@ func isWitnessProgram(pops []parsedOpcode) bool {
(len(pops[1].data) >= 2 && len(pops[1].data) <= 40) (len(pops[1].data) >= 2 && len(pops[1].data) <= 40)
} }
// IsNullData returns true if the passed script is a null data script, false
// otherwise.
func IsNullData(script []byte) bool {
pops, err := parseScript(script)
if err != nil {
return false
}
return isNullData(pops)
}
// ExtractWitnessProgramInfo attempts to extract the witness program version, // ExtractWitnessProgramInfo attempts to extract the witness program version,
// as well as the witness program itself from the passed script. // as well as the witness program itself from the passed script.
func ExtractWitnessProgramInfo(script []byte) (int, []byte, error) { func ExtractWitnessProgramInfo(script []byte) (int, []byte, error) {