From 7e036521d505708a3e0d0b3d9bbe1e4853111211 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Thu, 9 Mar 2017 16:45:14 -0500 Subject: [PATCH] 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 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- src/expvar/expvar_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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() -- 2.48.1