aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/encoding/binary
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2011-10-05 13:04:43 -0700
committerRobert Griesemer <gri@golang.org>2011-10-05 13:04:43 -0700
commitf7467e85e173bb029084b8d255fbb87595592d99 (patch)
tree5aca9fd42272a29c2c6a1e1d1a7b8a1ca8e9bad3 /src/pkg/encoding/binary
parent5d51b0ae53e92a315c1713430be9a914960fb7e4 (diff)
downloadgo-f7467e85e173bb029084b8d255fbb87595592d99.tar.xz
encoding/binary: added benchmarks
binary.BenchmarkPutUvarint32 20000000 85.6 ns/op binary.BenchmarkPutUvarint64 10000000 299 ns/op R=rsc CC=golang-dev https://golang.org/cl/5148049
Diffstat (limited to 'src/pkg/encoding/binary')
-rw-r--r--src/pkg/encoding/binary/varint_test.go26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/pkg/encoding/binary/varint_test.go b/src/pkg/encoding/binary/varint_test.go
index 1ceb4cd4b1..ef51f09293 100644
--- a/src/pkg/encoding/binary/varint_test.go
+++ b/src/pkg/encoding/binary/varint_test.go
@@ -11,8 +11,8 @@ import (
)
func testConstant(t *testing.T, w uint, max int) {
- var buf [MaxVarintLen64]byte
- n := PutUvarint(buf[:], 1<<w-1)
+ buf := make([]byte, MaxVarintLen64)
+ n := PutUvarint(buf, 1<<w-1)
if n != max {
t.Errorf("MaxVarintLen%d = %d; want %d", w, max, n)
}
@@ -25,7 +25,7 @@ func TestConstants(t *testing.T) {
}
func testVarint(t *testing.T, x int64) {
- var buf1 [10]byte
+ buf1 := make([]byte, MaxVarintLen64)
n := PutVarint(buf1[:], x)
y, m := Varint(buf1[0:n])
if x != y {
@@ -53,7 +53,7 @@ func testVarint(t *testing.T, x int64) {
}
func testUvarint(t *testing.T, x uint64) {
- var buf1 [10]byte
+ buf1 := make([]byte, MaxVarintLen64)
n := PutUvarint(buf1[:], x)
y, m := Uvarint(buf1[0:n])
if x != y {
@@ -162,3 +162,21 @@ func TestNonCanonicalZero(t *testing.T) {
}
}
+
+func BenchmarkPutUvarint32(b *testing.B) {
+ buf := make([]byte, MaxVarintLen32)
+ for i := 0; i < b.N; i++ {
+ for j := uint(0); j < MaxVarintLen32; j++ {
+ PutUvarint(buf, 1<<(j*7))
+ }
+ }
+}
+
+func BenchmarkPutUvarint64(b *testing.B) {
+ buf := make([]byte, MaxVarintLen64)
+ for i := 0; i < b.N; i++ {
+ for j := uint(0); j < MaxVarintLen64; j++ {
+ PutUvarint(buf, 1<<(j*7))
+ }
+ }
+}