Skip to content

Commit

Permalink
wire: Add large tx deserialize benchmark.
Browse files Browse the repository at this point in the history
This adds a benchmark for deserializing a large transaction that is
often referred to as the megatransaction since it is the largest Bitcoin
transaction mined to date.  It consists of 5569 inputs and 1 output and
its hash is:

bb41a757f405890fb0f5856228e23b715702d714d59bf2b1feb70d8b2b4e3e08.

This is being done so there is a benchmark that tests more of a
worst-case scenario which is a better candidate for identifying and
testing improvements.

The following benchmark results shows the how much more intensive this
transaction is over the existing mock transaction:

DeserializeTx       1000000    1751 ns/op      376 B/op     16 allocs/op
DeserializeTxLarge  300     5093980 ns/op  1672829 B/op  33430 allocs/op
  • Loading branch information
davecgh committed Apr 25, 2016
1 parent b87723c commit a092f16
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion wire/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ package wire

import (
"bytes"
"compress/bzip2"
"io/ioutil"
"os"
"testing"
"time"
)
Expand Down Expand Up @@ -306,7 +308,7 @@ func BenchmarkWriteTxIn(b *testing.B) {
}

// BenchmarkDeserializeTx performs a benchmark on how long it takes to
// deserialize a transaction.
// deserialize a small transaction.
func BenchmarkDeserializeTx(b *testing.B) {
buf := []byte{
0x01, 0x00, 0x00, 0x00, // Version
Expand Down Expand Up @@ -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))
}
}

Expand Down
Binary file added wire/testdata/megatx.bin.bz2
Binary file not shown.

0 comments on commit a092f16

Please sign in to comment.