From 76fcfbaa1f8e47c34f2a35ac9134c55c31d2d969 Mon Sep 17 00:00:00 2001
From: Dave Collins <davec@conformal.com>
Date: Wed, 13 Mar 2019 01:12:24 -0500
Subject: [PATCH] txscript: Add ExtractAtomicSwapDataPushes benches.

---
 txscript/bench_test.go | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/txscript/bench_test.go b/txscript/bench_test.go
index 26b7c9fe..456db25d 100644
--- a/txscript/bench_test.go
+++ b/txscript/bench_test.go
@@ -456,3 +456,44 @@ func BenchmarkPushedData(b *testing.B) {
 		}
 	}
 }
+
+// BenchmarkExtractAtomicSwapDataPushesLarge benchmarks how long it takes
+// ExtractAtomicSwapDataPushes to analyze a very large script.
+func BenchmarkExtractAtomicSwapDataPushesLarge(b *testing.B) {
+	script, err := genComplexScript()
+	if err != nil {
+		b.Fatalf("failed to create benchmark script: %v", err)
+	}
+
+	const scriptVersion = 0
+	b.ResetTimer()
+	b.ReportAllocs()
+	for i := 0; i < b.N; i++ {
+		_, err := ExtractAtomicSwapDataPushes(scriptVersion, script)
+		if err != nil {
+			b.Fatalf("unexpected err: %v", err)
+		}
+	}
+}
+
+// BenchmarkExtractAtomicSwapDataPushesLarge benchmarks how long it takes
+// ExtractAtomicSwapDataPushes to analyze a standard atomic swap script.
+func BenchmarkExtractAtomicSwapDataPushes(b *testing.B) {
+	secret := "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
+	recipient := "0000000000000000000000000000000000000001"
+	refund := "0000000000000000000000000000000000000002"
+	script := mustParseShortForm(fmt.Sprintf("IF SIZE 32 EQUALVERIFY SHA256 "+
+		"DATA_32 0x%s EQUALVERIFY DUP HASH160 DATA_20 0x%s ELSE 300000 "+
+		"CHECKLOCKTIMEVERIFY DROP DUP HASH160 DATA_20 0x%s ENDIF "+
+		"EQUALVERIFY CHECKSIG", secret, recipient, refund))
+
+	const scriptVersion = 0
+	b.ResetTimer()
+	b.ReportAllocs()
+	for i := 0; i < b.N; i++ {
+		_, err := ExtractAtomicSwapDataPushes(scriptVersion, script)
+		if err != nil {
+			b.Fatalf("unexpected err: %v", err)
+		}
+	}
+}