aboutsummaryrefslogtreecommitdiff
path: root/src/expvar
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2017-03-09 16:45:14 -0500
committerBryan Mills <bcmills@google.com>2017-03-10 19:09:48 +0000
commit7e036521d505708a3e0d0b3d9bbe1e4853111211 (patch)
tree438f68784c63c2b6b7de3ed4f8c5a8d58920048b /src/expvar
parentd9fe2332ba63d1dd9416438a53b58bd6a91626b6 (diff)
downloadgo-7e036521d505708a3e0d0b3d9bbe1e4853111211.tar.gz
go-7e036521d505708a3e0d0b3d9bbe1e4853111211.zip
expvar: add benchmark for (*Map).Set with per-goroutine keys
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>
Diffstat (limited to 'src/expvar')
-rw-r--r--src/expvar/expvar_test.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/expvar/expvar_test.go b/src/expvar/expvar_test.go
index 901d72201a..7ee66845cd 100644
--- a/src/expvar/expvar_test.go
+++ b/src/expvar/expvar_test.go
@@ -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()