Add benchmarks for readTxIn.
This commit adds a benchmark for the readTxIn function.
This commit is contained in:
parent
cece305f78
commit
1fe9f9e165
2 changed files with 26 additions and 4 deletions
|
@ -161,10 +161,7 @@ func BenchmarkReadTxOut(b *testing.B) {
|
||||||
}
|
}
|
||||||
var txOut btcwire.TxOut
|
var txOut btcwire.TxOut
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
err := btcwire.TstReadTxOut(bytes.NewBuffer(buf), 0, 0, &txOut)
|
btcwire.TstReadTxOut(bytes.NewBuffer(buf), 0, 0, &txOut)
|
||||||
if err != nil {
|
|
||||||
b.Log(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,3 +173,22 @@ func BenchmarkWriteTxOut(b *testing.B) {
|
||||||
btcwire.TstWriteTxOut(ioutil.Discard, 0, 0, txOut)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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 {
|
func TstWriteTxOut(w io.Writer, pver uint32, version uint32, to *TxOut) error {
|
||||||
return writeTxOut(w, pver, version, to)
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue