Skip to content

Commit

Permalink
txscript: Add ExtractPkScriptAddrs benchmarks.
Browse files Browse the repository at this point in the history
  • Loading branch information
davecgh authored and cfromknecht committed Feb 5, 2021
1 parent bf39ad7 commit 3b8712d
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions txscript/bench_test.go
Expand Up @@ -10,6 +10,7 @@ import (
"io/ioutil"
"testing"

"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/wire"
)

Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit 3b8712d

Please sign in to comment.