derp: add readUint32 and writeUint32 benchmarks
These aren't particularly performance critical,
but since I have an optimization pending for them,
it's worth having a corresponding benchmark.
"expvar"
"fmt"
"io"
+ "io/ioutil"
"net"
"reflect"
"sync"
@@ -803,3 +804,33 @@ func benchmarkSendRecvSize(b *testing.B, packetSize int) {
}
}
}
+
+func BenchmarkWriteUint32(b *testing.B) {
+ w := bufio.NewWriter(ioutil.Discard)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ writeUint32(w, 0x0ba3a)
+ }
+}
+
+type nopRead struct{}
+
+func (r nopRead) Read(p []byte) (int, error) {
+ return len(p), nil
+}
+
+var sinkU32 uint32
+
+func BenchmarkReadUint32(b *testing.B) {
+ r := bufio.NewReader(nopRead{})
+ var err error
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ sinkU32, err = readUint32(r)
+ if err != nil {
+ b.Fatal(err)
+ }
+ }
+}
