From: Brad Fitzpatrick Date: Fri, 29 Mar 2013 20:50:44 +0000 (-0700) Subject: runtime: additional map benchmarks for repeated lookups X-Git-Tag: go1.1rc2~268 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ecdcec1df2c06754ab39fb8d8154a7977fbd11f6;p=gostls13.git runtime: additional map benchmarks for repeated lookups For the future. Update #5147 R=khr, r CC=golang-dev https://golang.org/cl/8165044 --- diff --git a/src/pkg/runtime/mapspeed_test.go b/src/pkg/runtime/mapspeed_test.go index a379740606..4d77347b24 100644 --- a/src/pkg/runtime/mapspeed_test.go +++ b/src/pkg/runtime/mapspeed_test.go @@ -138,6 +138,7 @@ func BenchmarkSmallStrMap(b *testing.B) { _, _ = m[key] } } + func BenchmarkIntMap(b *testing.B) { m := make(map[int]bool) for i := 0; i < 8; i++ { @@ -148,3 +149,25 @@ func BenchmarkIntMap(b *testing.B) { _, _ = m[7] } } + +// Accessing the same keys in a row. +func benchmarkRepeatedLookup(b *testing.B, lookupKeySize int) { + m := make(map[string]bool) + // At least bigger than a single bucket: + for i := 0; i < 64; i++ { + m[fmt.Sprintf("some key %d", i)] = true + } + base := strings.Repeat("x", lookupKeySize-1) + key1 := base + "1" + key2 := base + "2" + b.ResetTimer() + for i := 0; i < b.N/4; i++ { + _ = m[key1] + _ = m[key1] + _ = m[key2] + _ = m[key2] + } +} + +func BenchmarkRepeatedLookupStrMapKey32(b *testing.B) { benchmarkRepeatedLookup(b, 32) } +func BenchmarkRepeatedLookupStrMapKey1M(b *testing.B) { benchmarkRepeatedLookup(b, 1<<20) }