wire: Add large tx deserialize benchmark. (#678)
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: DeserializeTxSmall 1000000 1751 ns/op 376 B/op 16 allocs/op DeserializeTxLarge 300 5093980 ns/op 1672829 B/op 33430 allocs/op
This commit is contained in:
parent
de4fb24389
commit
27c0f9f8d1
2 changed files with 24 additions and 2 deletions
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
BIN
wire/testdata/megatx.bin.bz2
vendored
Normal file
BIN
wire/testdata/megatx.bin.bz2
vendored
Normal file
Binary file not shown.
Loading…
Reference in a new issue