diff --git a/wire/bench_test.go b/wire/bench_test.go index cef5af4fc..31e62ef44 100644 --- a/wire/bench_test.go +++ b/wire/bench_test.go @@ -6,7 +6,9 @@ package wire import ( "bytes" + "compress/bzip2" "io/ioutil" + "os" "testing" "time" ) @@ -306,8 +308,8 @@ func BenchmarkWriteTxIn(b *testing.B) { } // BenchmarkDeserializeTx performs a benchmark on how long it takes to -// deserialize a transaction. -func BenchmarkDeserializeTx(b *testing.B) { +// deserialize a small transaction. +func BenchmarkDeserializeTxSmall(b *testing.B) { buf := []byte{ 0x01, 0x00, 0x00, 0x00, // Version 0x01, // Varint for number of input transactions @@ -338,7 +340,27 @@ func BenchmarkDeserializeTx(b *testing.B) { var tx MsgTx for i := 0; i < b.N; i++ { tx.Deserialize(bytes.NewReader(buf)) + } +} +// BenchmarkDeserializeTxLarge performs a benchmark on how long it takes to +// deserialize a very large transaction. +func BenchmarkDeserializeTxLarge(b *testing.B) { + // tx bb41a757f405890fb0f5856228e23b715702d714d59bf2b1feb70d8b2b4e3e08 + // from the main block chain. + fi, err := os.Open("testdata/megatx.bin.bz2") + if err != nil { + b.Fatalf("Failed to read transaction data: %v", err) + } + defer fi.Close() + buf, err := ioutil.ReadAll(bzip2.NewReader(fi)) + if err != nil { + b.Fatalf("Failed to read transaction data: %v", err) + } + + var tx MsgTx + for i := 0; i < b.N; i++ { + tx.Deserialize(bytes.NewReader(buf)) } } diff --git a/wire/testdata/megatx.bin.bz2 b/wire/testdata/megatx.bin.bz2 new file mode 100644 index 000000000..0e71e5b41 Binary files /dev/null and b/wire/testdata/megatx.bin.bz2 differ