From a6106eef379ef560016d0dcdbdd9c9c86b7cd39c Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 15 Nov 2011 13:59:59 -0500 Subject: [PATCH] encoding/json: make BenchmarkSkipValue more consistent 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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pkg/encoding/json/scanner_test.go b/src/pkg/encoding/json/scanner_test.go index a0a5995af8..14d850865a 100644 --- a/src/pkg/encoding/json/scanner_test.go +++ b/src/pkg/encoding/json/scanner_test.go @@ -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))) }