Add benchmarks for readTxIn.

This commit adds a benchmark for the readTxIn function.
This commit is contained in:
Dave Collins 2013-11-06 16:06:53 -06:00
parent cece305f78
commit 1fe9f9e165
2 changed files with 26 additions and 4 deletions

View file

@ -161,10 +161,7 @@ func BenchmarkReadTxOut(b *testing.B) {
}
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)
}
btcwire.TstReadTxOut(bytes.NewBuffer(buf), 0, 0, &txOut)
}
}
@ -176,3 +173,22 @@ func BenchmarkWriteTxOut(b *testing.B) {
btcwire.TstWriteTxOut(ioutil.Discard, 0, 0, txOut)
}
}
// BenchmarkReadTxIn performs a benchmark on how long it takes to read a
// transaction input.
func BenchmarkReadTxIn(b *testing.B) {
buf := []byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Previous output hash
0xff, 0xff, 0xff, 0xff, // Previous output index
0x07, // Varint for length of signature script
0x04, 0xff, 0xff, 0x00, 0x1d, 0x01, 0x04, // Signature script
0xff, 0xff, 0xff, 0xff, // Sequence
}
var txIn btcwire.TxIn
for i := 0; i < b.N; i++ {
btcwire.TstReadTxIn(bytes.NewBuffer(buf), 0, 0, &txIn)
}
}

View file

@ -126,3 +126,9 @@ func TstReadTxOut(r io.Reader, pver uint32, version uint32, to *TxOut) error {
func TstWriteTxOut(w io.Writer, pver uint32, version uint32, to *TxOut) error {
return writeTxOut(w, pver, version, to)
}
// TstReadTxIn makes the internal readTxIn function available to the test
// package.
func TstReadTxIn(r io.Reader, pver uint32, version uint32, ti *TxIn) error {
return readTxIn(r, pver, version, ti)
}