Skip to content

Commit 37569ff

Browse files
author
Bryan C. Mills
committed
syncmap: add benchmark for Range
adjust BenchmarkAdversarialDelete to be somewhat more adversarial. updates golang/go#18177 Change-Id: Id01ed1077a0447dcfc6ea3929c22baaddbc9d6ee Reviewed-on: https://go-review.googlesource.com/37151 Reviewed-by: Russ Cox <[email protected]>
1 parent 54b13b0 commit 37569ff

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

syncmap/map_bench_test.go

+23-4
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,27 @@ func BenchmarkLoadOrStoreCollision(b *testing.B) {
145145
})
146146
}
147147

148+
func BenchmarkRange(b *testing.B) {
149+
const mapSize = 1 << 10
150+
151+
benchMap(b, bench{
152+
setup: func(_ *testing.B, m mapInterface) {
153+
for i := 0; i < mapSize; i++ {
154+
m.Store(i, i)
155+
}
156+
},
157+
158+
perG: func(b *testing.B, pb *testing.PB, i int, m mapInterface) {
159+
for ; pb.Next(); i++ {
160+
m.Range(func(_, _ interface{}) bool { return true })
161+
}
162+
},
163+
})
164+
}
165+
148166
// BenchmarkAdversarialAlloc tests performance when we store a new value
149-
// immediately whenever the map is promoted to clean.
167+
// immediately whenever the map is promoted to clean and otherwise load a
168+
// unique, missing key.
150169
//
151170
// This forces the Load calls to always acquire the map's mutex.
152171
func BenchmarkAdversarialAlloc(b *testing.B) {
@@ -165,8 +184,8 @@ func BenchmarkAdversarialAlloc(b *testing.B) {
165184
})
166185
}
167186

168-
// BenchmarkAdversarialDelete tests performance when we delete and restore a
169-
// value immediately after a large map has been promoted.
187+
// BenchmarkAdversarialDelete tests performance when we periodically delete
188+
// one key and add a different one in a large map.
170189
//
171190
// This forces the Load calls to always acquire the map's mutex and periodically
172191
// makes a full copy of the map despite changing only one entry.
@@ -191,7 +210,7 @@ func BenchmarkAdversarialDelete(b *testing.B) {
191210
return false
192211
})
193212
m.Delete(key)
194-
m.Store(key, key)
213+
m.Store(i, i)
195214
}
196215
}
197216
},

0 commit comments

Comments
 (0)