]> Cypherpunks repositories - gostls13.git/commitdiff
expvar: make BenchmarkAdd{Same,Different} comparable to 1.8
authorBryan C. Mills <bcmills@google.com>
Fri, 10 Feb 2017 19:46:22 +0000 (14:46 -0500)
committerBryan Mills <bcmills@google.com>
Fri, 10 Feb 2017 20:08:14 +0000 (20:08 +0000)
bradfitz noted in change 36717 that the new behavior was no longer
comparable with the old.  This change restores comparable behavior
for -cpu=1.

BenchmarkMapAddSame                 909           909           +0.00%
BenchmarkMapAddSame-6               1309          262           -79.98%
BenchmarkMapAddDifferent            2856          3030          +6.09%
BenchmarkMapAddDifferent-6          3803          581           -84.72%

updates #18177

Change-Id: Ifaff5a1f48be92002d86c296220313b7efdc81d6
Reviewed-on: https://go-review.googlesource.com/36723
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/expvar/expvar_test.go

index f802cfd37e360c42e9873a648dfd22092e5d3c3e..2a4a21ec7b3c86b6400df774333b6cab5aa660c2 100644 (file)
@@ -221,11 +221,12 @@ func BenchmarkMapSet(b *testing.B) {
 }
 
 func BenchmarkMapAddSame(b *testing.B) {
-       m := new(Map).Init()
-       b.ResetTimer()
-
        b.RunParallel(func(pb *testing.PB) {
                for pb.Next() {
+                       m := new(Map).Init()
+                       m.Add("red", 1)
+                       m.Add("red", 1)
+                       m.Add("red", 1)
                        m.Add("red", 1)
                }
        })
@@ -241,19 +242,17 @@ func BenchmarkMapAddDifferent(b *testing.B) {
                procKeys[i] = keys
        }
 
-       m := new(Map).Init()
        b.ResetTimer()
 
        var n int32
        b.RunParallel(func(pb *testing.PB) {
                i := int(atomic.AddInt32(&n, 1)-1) % len(procKeys)
                keys := procKeys[i]
-               j := 0
 
                for pb.Next() {
-                       m.Add(keys[j], 1)
-                       if j++; j == len(keys) {
-                               j = 0
+                       m := new(Map).Init()
+                       for _, k := range keys {
+                               m.Add(k, 1)
                        }
                }
        })