Add benchmarks for writeTxOut.
This commit adds a benchmark for the writeTxOut function.
This commit is contained in:
parent
48c350f379
commit
ab8c8e2d39
3 changed files with 17 additions and 2 deletions
|
@ -140,3 +140,12 @@ func BenchmarkWriteOutPoint(b *testing.B) {
|
||||||
btcwire.TstWriteOutPoint(ioutil.Discard, 0, 0, op)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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 {
|
func TstWriteOutPoint(w io.Writer, pver uint32, version uint32, op *OutPoint) error {
|
||||||
return writeOutPoint(w, pver, version, op)
|
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)
|
||||||
|
}
|
||||||
|
|
4
msgtx.go
4
msgtx.go
|
@ -339,7 +339,7 @@ func (msg *MsgTx) BtcEncode(w io.Writer, pver uint32) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, to := range msg.TxOut {
|
for _, to := range msg.TxOut {
|
||||||
err = writeTxOut(w, pver, to)
|
err = writeTxOut(w, pver, msg.Version, to)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
// writeTxOut encodes to into the bitcoin protocol encoding for a transaction
|
||||||
// output (TxOut) to w.
|
// 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)
|
err := writeElement(w, to.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue