Add benchmarks for readVarInt.

This commit adds a few benchmarks for the readVarInt function.
This commit is contained in:
Dave Collins 2013-11-05 21:35:28 -06:00
parent 50c10faf4e
commit 87ce23d679

View file

@ -5,6 +5,7 @@
package btcwire_test
import (
"bytes"
"github.com/conformal/btcwire"
"io/ioutil"
"testing"
@ -41,3 +42,39 @@ func BenchmarkWriteVarInt9(b *testing.B) {
btcwire.TstWriteVarInt(ioutil.Discard, 0, 18446744073709551615)
}
}
// BenchmarkReadVarInt1 performs a benchmark on how long it takes to write
// a single byte variable length integer.
func BenchmarkReadVarInt1(b *testing.B) {
buf := []byte{0x01}
for i := 0; i < b.N; i++ {
btcwire.TstReadVarInt(bytes.NewBuffer(buf), 0)
}
}
// BenchmarkReadVarInt3 performs a benchmark on how long it takes to write
// a three byte variable length integer.
func BenchmarkReadVarInt3(b *testing.B) {
buf := []byte{0x0fd, 0xff, 0xff}
for i := 0; i < b.N; i++ {
btcwire.TstReadVarInt(bytes.NewBuffer(buf), 0)
}
}
// BenchmarkReadVarInt5 performs a benchmark on how long it takes to write
// a five byte variable length integer.
func BenchmarkReadVarInt5(b *testing.B) {
buf := []byte{0xfe, 0xff, 0xff, 0xff, 0xff}
for i := 0; i < b.N; i++ {
btcwire.TstReadVarInt(bytes.NewBuffer(buf), 0)
}
}
// BenchmarkReadVarInt9 performs a benchmark on how long it takes to write
// a nine byte variable length integer.
func BenchmarkReadVarInt9(b *testing.B) {
buf := []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
for i := 0; i < b.N; i++ {
btcwire.TstReadVarInt(bytes.NewBuffer(buf), 0)
}
}