mirror of
https://github.com/tailscale/tailscale.git
synced 2025-03-28 12:02:23 +00:00
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. Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
This commit is contained in:
parent
25b021388b
commit
355c6296f0
@ -12,6 +12,7 @@ import (
|
|||||||
"expvar"
|
"expvar"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sync"
|
"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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user