( b *testing.B, n int, genKeys func(start, end int) []T, )
| 253 | } |
| 254 | |
| 255 | func 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 | |
| 280 | func benchmarkSwissMapGetHit[T benchTypes](b *testing.B, n int, genKeys func(start, end int) []T) { |
| 281 | c := perfbench.Open(b) |
nothing calls this directly
no test coverage detected
searching dependent graphs…