diff --git a/txscript/bench_test.go b/txscript/bench_test.go index 456db25d..cac29202 100644 --- a/txscript/bench_test.go +++ b/txscript/bench_test.go @@ -10,6 +10,7 @@ import ( "io/ioutil" "testing" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/wire" ) @@ -497,3 +498,40 @@ func BenchmarkExtractAtomicSwapDataPushes(b *testing.B) { } } } + +// BenchmarkExtractPkScriptAddrsLarge benchmarks how long it takes to analyze +// and potentially extract addresses from a very large non-standard script. +func BenchmarkExtractPkScriptAddrsLarge(b *testing.B) { + script, err := genComplexScript() + if err != nil { + b.Fatalf("failed to create benchmark script: %v", err) + } + + params := &chaincfg.MainNetParams + b.ResetTimer() + b.ReportAllocs() + for i := 0; i < b.N; i++ { + _, _, _, err := ExtractPkScriptAddrs(script, params) + if err != nil { + b.Fatalf("unexpected err: %v", err) + } + } +} + +// BenchmarkExtractPkScriptAddrs benchmarks how long it takes to analyze and +// potentially extract addresses from a typical script. +func BenchmarkExtractPkScriptAddrs(b *testing.B) { + script := mustParseShortForm("OP_DUP HASH160 " + + "DATA_20 0x0102030405060708090a0b0c0d0e0f1011121314 " + + "EQUAL") + + params := &chaincfg.MainNetParams + b.ResetTimer() + b.ReportAllocs() + for i := 0; i < b.N; i++ { + _, _, _, err := ExtractPkScriptAddrs(script, params) + if err != nil { + b.Fatalf("unexpected err: %v", err) + } + } +}