Add benchmarks for readOutPoint.

This commit adds a benchmark for the readOutPoint function.
This commit is contained in:
Dave Collins 2013-11-06 07:33:37 -06:00
parent f54b010e4b
commit d63e0dd455
2 changed files with 23 additions and 1 deletions

View file

@ -106,13 +106,29 @@ func BenchmarkWriteVarStr4(b *testing.B) {
} }
// BenchmarkWriteVarStr10 performs a benchmark on how long it takes to write a // BenchmarkWriteVarStr10 performs a benchmark on how long it takes to write a
// four byte variable length string. // ten byte variable length string.
func BenchmarkWriteVarStr10(b *testing.B) { func BenchmarkWriteVarStr10(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
btcwire.TstWriteVarString(ioutil.Discard, 0, "test012345") btcwire.TstWriteVarString(ioutil.Discard, 0, "test012345")
} }
} }
// BenchmarkReadOutPoint performs a benchmark on how long it takes to read a
// transaction output point.
func BenchmarkReadOutPoint(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
}
var op btcwire.OutPoint
for i := 0; i < b.N; i++ {
btcwire.TstReadOutPoint(bytes.NewBuffer(buf), 0, 0, &op)
}
}
// BenchmarkWriteOutPoint performs a benchmark on how long it takes to write a // BenchmarkWriteOutPoint performs a benchmark on how long it takes to write a
// transaction output point. // transaction output point.
func BenchmarkWriteOutPoint(b *testing.B) { func BenchmarkWriteOutPoint(b *testing.B) {

View file

@ -103,6 +103,12 @@ func TstReadMessageHeader(r io.Reader) (*messageHeader, error) {
return readMessageHeader(r) return readMessageHeader(r)
} }
// TstReadOutPoint makes the internal readOutPoint function available to the
// test package.
func TstReadOutPoint(r io.Reader, pver uint32, version uint32, op *OutPoint) error {
return readOutPoint(r, pver, version, op)
}
// TstWriteOutPoint makes the internal writeOutPoint function available to the // TstWriteOutPoint makes the internal writeOutPoint function available to the
// test package. // test package.
func TstWriteOutPoint(w io.Writer, pver uint32, version uint32, op *OutPoint) error { func TstWriteOutPoint(w io.Writer, pver uint32, version uint32, op *OutPoint) error {