]> Cypherpunks repositories - gostls13.git/commitdiff
bytes: Benchmark Buffer's compactions
authorRobert Obryk <robryk@gmail.com>
Fri, 29 Mar 2013 21:17:09 +0000 (14:17 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 29 Mar 2013 21:17:09 +0000 (14:17 -0700)
This benchmark verifies that CL #8173043 reduces time spent
sliding the Buffer's contents.

Results without and with CL #8173043 applied:
benchmark                        old ns/op    new ns/op    delta
BenchmarkBufferFullSmallReads       755336       175054  -76.82%

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/8174043

src/pkg/bytes/buffer_test.go

index 5b0b8b50cf7f6fc4232de039bd2e5efb1d58258a..75145b05e92df6619214c142c67644af89988eef 100644 (file)
@@ -509,3 +509,19 @@ func BenchmarkBufferNotEmptyWriteRead(b *testing.B) {
                }
        }
 }
+
+// Check that we don't compact too often. From Issue 5154.
+func BenchmarkBufferFullSmallReads(b *testing.B) {
+       buf := make([]byte, 1024)
+       for i := 0; i < b.N; i++ {
+               var b Buffer
+               b.Write(buf)
+               for b.Len()+20 < b.Cap() {
+                       b.Write(buf[:10])
+               }
+               for i := 0; i < 5<<10; i++ {
+                       b.Read(buf[:1])
+                       b.Write(buf[:1])
+               }
+       }
+}