Add benchmarks for writeTxOut.

This commit adds a benchmark for the writeTxOut function.
This commit is contained in:
Dave Collins 2013-11-06 15:21:37 -06:00
parent 48c350f379
commit ab8c8e2d39
3 changed files with 17 additions and 2 deletions

View file

@ -140,3 +140,12 @@ func BenchmarkWriteOutPoint(b *testing.B) {
btcwire.TstWriteOutPoint(ioutil.Discard, 0, 0, op)
}
}
// BenchmarkWriteTxOut performs a benchmark on how long it takes to write
// a transaction output.
func BenchmarkWriteTxOut(b *testing.B) {
txOut := blockOne.Transactions[0].TxOut[0]
for i := 0; i < b.N; i++ {
btcwire.TstWriteTxOut(ioutil.Discard, 0, 0, txOut)
}
}

View file

@ -114,3 +114,9 @@ func TstReadOutPoint(r io.Reader, pver uint32, version uint32, op *OutPoint) err
func TstWriteOutPoint(w io.Writer, pver uint32, version uint32, op *OutPoint) error {
return writeOutPoint(w, pver, version, op)
}
// TstWriteTxOut makes the internal writeTxOut function available to the test
// package.
func TstWriteTxOut(w io.Writer, pver uint32, version uint32, to *TxOut) error {
return writeTxOut(w, pver, version, to)
}

View file

@ -339,7 +339,7 @@ func (msg *MsgTx) BtcEncode(w io.Writer, pver uint32) error {
}
for _, to := range msg.TxOut {
err = writeTxOut(w, pver, to)
err = writeTxOut(w, pver, msg.Version, to)
if err != nil {
return err
}
@ -551,7 +551,7 @@ func readTxOut(r io.Reader, pver uint32, version uint32, to *TxOut) error {
// writeTxOut encodes to into the bitcoin protocol encoding for a transaction
// output (TxOut) to w.
func writeTxOut(w io.Writer, pver uint32, to *TxOut) error {
func writeTxOut(w io.Writer, pver uint32, version uint32, to *TxOut) error {
err := writeElement(w, to.Value)
if err != nil {
return err