MCPcopy Create free account
hub / github.com/cockroachdb/swiss / benchmarkRuntimeMapGetHit

Function benchmarkRuntimeMapGetHit

bench_test.go:255–278  ·  view source on GitHub ↗
(
	b *testing.B, n int, genKeys func(start, end int) []T,
)

Source from the content-addressed store, hash-verified

253}
254
255func benchmarkRuntimeMapGetHit[T benchTypes](
256 b *testing.B, n int, genKeys func(start, end int) []T,
257) {
258 c := perfbench.Open(b)
259
260 m := make(map[T]T, n)
261 keys := genKeys(0, n)
262 for _, k := range keys {
263 m[k] = k
264 }
265
266 // Go's builtin map has an optimization to avoid string comparisons if
267 // there is pointer equality. Defeat this optimization to get a better
268 // apples-to-apples comparison. This is reasonable to do because looking
269 // up a value by a string key which shares the underlying string data with
270 // the element in the map is a rare pattern.
271 keys = genKeys(0, n)
272
273 b.ResetTimer()
274 c.Reset()
275 for i := 0; i < b.N; i++ {
276 _ = m[keys[i%n]]
277 }
278}
279
280func benchmarkSwissMapGetHit[T benchTypes](b *testing.B, n int, genKeys func(start, end int) []T) {
281 c := perfbench.Open(b)

Callers

nothing calls this directly

Calls 1

genKeysFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…