]> Cypherpunks.ru repositories - gostls13.git/commitdiff
expvar: add benchmark for (*Map).Set with per-goroutine keys
authorBryan C. Mills <bcmills@google.com>
Thu, 9 Mar 2017 21:45:14 +0000 (16:45 -0500)
committerBryan Mills <bcmills@google.com>
Fri, 10 Mar 2017 19:09:48 +0000 (19:09 +0000)
Change-Id: I0fa68ca9812fe5e82ffb9d0b9598e95b47183eb8
Reviewed-on: https://go-review.googlesource.com/38011
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/expvar/expvar_test.go

index 901d72201adc3289646b14c6d651ef67cb3a836a..7ee66845cd6e2fbafee3c67cde275e0bd414ad44 100644 (file)
@@ -211,6 +211,33 @@ func BenchmarkMapSet(b *testing.B) {
        })
 }
 
+func BenchmarkMapSetDifferent(b *testing.B) {
+       procKeys := make([][]string, runtime.GOMAXPROCS(0))
+       for i := range procKeys {
+               keys := make([]string, 4)
+               for j := range keys {
+                       keys[j] = fmt.Sprint(i, j)
+               }
+               procKeys[i] = keys
+       }
+
+       m := new(Map).Init()
+       v := new(Int)
+       b.ResetTimer()
+
+       var n int32
+       b.RunParallel(func(pb *testing.PB) {
+               i := int(atomic.AddInt32(&n, 1)-1) % len(procKeys)
+               keys := procKeys[i]
+
+               for pb.Next() {
+                       for _, k := range keys {
+                               m.Set(k, v)
+                       }
+               }
+       })
+}
+
 func BenchmarkMapSetString(b *testing.B) {
        m := new(Map).Init()