aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2024-11-11 16:07:58 -0500
committerGopher Robot <gobot@golang.org>2024-11-13 18:14:14 +0000
commit6e9c56e26b1ed26cb0dc81a6aeb974e675a9ce9e (patch)
tree01a24e949f5436c8b2a7f22597984c1d143a34c1 /src/runtime
parent5e91059f8b5cc078b4b0bfa38290a98414e441e2 (diff)
downloadgo-6e9c56e26b1ed26cb0dc81a6aeb974e675a9ce9e.tar.xz
runtime: add benchmark of iteration over map with low load
Change-Id: I3a3b7da6245a18bf1db0c595008f0eea853ce544 Reviewed-on: https://go-review.googlesource.com/c/go/+/627155 Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/map_benchmark_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/runtime/map_benchmark_test.go b/src/runtime/map_benchmark_test.go
index 5f03042649..205647113f 100644
--- a/src/runtime/map_benchmark_test.go
+++ b/src/runtime/map_benchmark_test.go
@@ -714,6 +714,42 @@ func BenchmarkMapIter(b *testing.B) {
b.Run("Key=int32/Elem=*int32", benchSizes(benchmarkMapIter[int32, *int32]))
}
+func benchmarkMapIterLowLoad[K mapBenchmarkKeyType, E mapBenchmarkElemType](b *testing.B, n int) {
+ // Only insert one entry regardless of map size.
+ k := genValues[K](0, 1)
+ e := genValues[E](0, 1)
+
+ m := make(map[K]E, n)
+ for i := range k {
+ m[k[i]] = e[i]
+ }
+
+ iterations := iterCount(b, n)
+ sinkK := newSink[K]()
+ sinkE := newSink[E]()
+ b.ResetTimer()
+
+ for i := 0; i < iterations; i++ {
+ for k, e := range m {
+ *sinkK = k
+ *sinkE = e
+ }
+ }
+}
+
+func BenchmarkMapIterLowLoad(b *testing.B) {
+ b.Run("Key=int32/Elem=int32", benchSizes(benchmarkMapIterLowLoad[int32, int32]))
+ b.Run("Key=int64/Elem=int64", benchSizes(benchmarkMapIterLowLoad[int64, int64]))
+ b.Run("Key=string/Elem=string", benchSizes(benchmarkMapIterLowLoad[string, string]))
+ b.Run("Key=smallType/Elem=int32", benchSizes(benchmarkMapIterLowLoad[smallType, int32]))
+ b.Run("Key=mediumType/Elem=int32", benchSizes(benchmarkMapIterLowLoad[mediumType, int32]))
+ b.Run("Key=bigType/Elem=int32", benchSizes(benchmarkMapIterLowLoad[bigType, int32]))
+ b.Run("Key=bigType/Elem=bigType", benchSizes(benchmarkMapIterLowLoad[bigType, bigType]))
+ b.Run("Key=int32/Elem=bigType", benchSizes(benchmarkMapIterLowLoad[int32, bigType]))
+ b.Run("Key=*int32/Elem=int32", benchSizes(benchmarkMapIterLowLoad[*int32, int32]))
+ b.Run("Key=int32/Elem=*int32", benchSizes(benchmarkMapIterLowLoad[int32, *int32]))
+}
+
func benchmarkMapAccessHit[K mapBenchmarkKeyType, E mapBenchmarkElemType](b *testing.B, n int) {
if n == 0 {
b.Skip("can't access empty map")