]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/json: make BenchmarkSkipValue more consistent
authorRuss Cox <rsc@golang.org>
Tue, 15 Nov 2011 18:59:59 +0000 (13:59 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 15 Nov 2011 18:59:59 +0000 (13:59 -0500)
Move scanner allocation out of loop.
It's the only allocation in the test so it dominates
when it triggers a garbage collection.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5369117

src/pkg/encoding/json/scanner_test.go

index a0a5995af8ffb1e695264c10067974780be2b271..14d850865a673c3d387cd847ee2720a9503a0bff 100644 (file)
@@ -186,11 +186,12 @@ func TestNextValueBig(t *testing.T) {
        }
 }
 
+var benchScan scanner
+
 func BenchmarkSkipValue(b *testing.B) {
        initBig()
-       var scan scanner
        for i := 0; i < b.N; i++ {
-               nextValue(jsonBig, &scan)
+               nextValue(jsonBig, &benchScan)
        }
        b.SetBytes(int64(len(jsonBig)))
 }