File tree 1 file changed +23
-0
lines changed
1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -138,6 +138,7 @@ func BenchmarkSmallStrMap(b *testing.B) {
138
138
_ , _ = m [key ]
139
139
}
140
140
}
141
+
141
142
func BenchmarkIntMap (b * testing.B ) {
142
143
m := make (map [int ]bool )
143
144
for i := 0 ; i < 8 ; i ++ {
@@ -148,3 +149,25 @@ func BenchmarkIntMap(b *testing.B) {
148
149
_ , _ = m [7 ]
149
150
}
150
151
}
152
+
153
+ // Accessing the same keys in a row.
154
+ func benchmarkRepeatedLookup (b * testing.B , lookupKeySize int ) {
155
+ m := make (map [string ]bool )
156
+ // At least bigger than a single bucket:
157
+ for i := 0 ; i < 64 ; i ++ {
158
+ m [fmt .Sprintf ("some key %d" , i )] = true
159
+ }
160
+ base := strings .Repeat ("x" , lookupKeySize - 1 )
161
+ key1 := base + "1"
162
+ key2 := base + "2"
163
+ b .ResetTimer ()
164
+ for i := 0 ; i < b .N / 4 ; i ++ {
165
+ _ = m [key1 ]
166
+ _ = m [key1 ]
167
+ _ = m [key2 ]
168
+ _ = m [key2 ]
169
+ }
170
+ }
171
+
172
+ func BenchmarkRepeatedLookupStrMapKey32 (b * testing.B ) { benchmarkRepeatedLookup (b , 32 ) }
173
+ func BenchmarkRepeatedLookupStrMapKey1M (b * testing.B ) { benchmarkRepeatedLookup (b , 1 << 20 ) }
You can’t perform that action at this time.
0 commit comments