Add benchmarks for readTxOut.

This commit adds a benchmark for the readTxOut function.
This commit is contained in:
Dave Collins 2013-11-06 15:40:46 -06:00
parent a7e3ee6aeb
commit 0228508172
2 changed files with 33 additions and 0 deletions

View file

@ -141,6 +141,33 @@ func BenchmarkWriteOutPoint(b *testing.B) {
} }
} }
// BenchmarkReadTxOut performs a benchmark on how long it takes to read a
// transaction output.
func BenchmarkReadTxOut(b *testing.B) {
buf := []byte{
0x00, 0xf2, 0x05, 0x2a, 0x01, 0x00, 0x00, 0x00, // Transaction amount
0x43, // Varint for length of pk script
0x41, // OP_DATA_65
0x04, 0x96, 0xb5, 0x38, 0xe8, 0x53, 0x51, 0x9c,
0x72, 0x6a, 0x2c, 0x91, 0xe6, 0x1e, 0xc1, 0x16,
0x00, 0xae, 0x13, 0x90, 0x81, 0x3a, 0x62, 0x7c,
0x66, 0xfb, 0x8b, 0xe7, 0x94, 0x7b, 0xe6, 0x3c,
0x52, 0xda, 0x75, 0x89, 0x37, 0x95, 0x15, 0xd4,
0xe0, 0xa6, 0x04, 0xf8, 0x14, 0x17, 0x81, 0xe6,
0x22, 0x94, 0x72, 0x11, 0x66, 0xbf, 0x62, 0x1e,
0x73, 0xa8, 0x2c, 0xbf, 0x23, 0x42, 0xc8, 0x58,
0xee, // 65-byte signature
0xac, // OP_CHECKSIG
}
var txOut btcwire.TxOut
for i := 0; i < b.N; i++ {
err := btcwire.TstReadTxOut(bytes.NewBuffer(buf), 0, 0, &txOut)
if err != nil {
b.Log(err)
}
}
}
// BenchmarkWriteTxOut performs a benchmark on how long it takes to write // BenchmarkWriteTxOut performs a benchmark on how long it takes to write
// a transaction output. // a transaction output.
func BenchmarkWriteTxOut(b *testing.B) { func BenchmarkWriteTxOut(b *testing.B) {

View file

@ -115,6 +115,12 @@ func TstWriteOutPoint(w io.Writer, pver uint32, version uint32, op *OutPoint) er
return writeOutPoint(w, pver, version, op) return writeOutPoint(w, pver, version, op)
} }
// TstReadTxOut makes the internal readTxOut function available to the test
// package.
func TstReadTxOut(r io.Reader, pver uint32, version uint32, to *TxOut) error {
return readTxOut(r, pver, version, to)
}
// TstWriteTxOut makes the internal writeTxOut function available to the test // TstWriteTxOut makes the internal writeTxOut function available to the test
// package. // package.
func TstWriteTxOut(w io.Writer, pver uint32, version uint32, to *TxOut) error { func TstWriteTxOut(w io.Writer, pver uint32, version uint32, to *TxOut) error {