@@ -714,6 +714,42 @@ func BenchmarkMapIter(b *testing.B) {
714
714
b .Run ("Key=int32/Elem=*int32" , benchSizes (benchmarkMapIter [int32 , * int32 ]))
715
715
}
716
716
717
+ func benchmarkMapIterLowLoad [K mapBenchmarkKeyType , E mapBenchmarkElemType ](b * testing.B , n int ) {
718
+ // Only insert one entry regardless of map size.
719
+ k := genValues [K ](0 , 1 )
720
+ e := genValues [E ](0 , 1 )
721
+
722
+ m := make (map [K ]E , n )
723
+ for i := range k {
724
+ m [k [i ]] = e [i ]
725
+ }
726
+
727
+ iterations := iterCount (b , n )
728
+ sinkK := newSink [K ]()
729
+ sinkE := newSink [E ]()
730
+ b .ResetTimer ()
731
+
732
+ for i := 0 ; i < iterations ; i ++ {
733
+ for k , e := range m {
734
+ * sinkK = k
735
+ * sinkE = e
736
+ }
737
+ }
738
+ }
739
+
740
+ func BenchmarkMapIterLowLoad (b * testing.B ) {
741
+ b .Run ("Key=int32/Elem=int32" , benchSizes (benchmarkMapIterLowLoad [int32 , int32 ]))
742
+ b .Run ("Key=int64/Elem=int64" , benchSizes (benchmarkMapIterLowLoad [int64 , int64 ]))
743
+ b .Run ("Key=string/Elem=string" , benchSizes (benchmarkMapIterLowLoad [string , string ]))
744
+ b .Run ("Key=smallType/Elem=int32" , benchSizes (benchmarkMapIterLowLoad [smallType , int32 ]))
745
+ b .Run ("Key=mediumType/Elem=int32" , benchSizes (benchmarkMapIterLowLoad [mediumType , int32 ]))
746
+ b .Run ("Key=bigType/Elem=int32" , benchSizes (benchmarkMapIterLowLoad [bigType , int32 ]))
747
+ b .Run ("Key=bigType/Elem=bigType" , benchSizes (benchmarkMapIterLowLoad [bigType , bigType ]))
748
+ b .Run ("Key=int32/Elem=bigType" , benchSizes (benchmarkMapIterLowLoad [int32 , bigType ]))
749
+ b .Run ("Key=*int32/Elem=int32" , benchSizes (benchmarkMapIterLowLoad [* int32 , int32 ]))
750
+ b .Run ("Key=int32/Elem=*int32" , benchSizes (benchmarkMapIterLowLoad [int32 , * int32 ]))
751
+ }
752
+
717
753
func benchmarkMapAccessHit [K mapBenchmarkKeyType , E mapBenchmarkElemType ](b * testing.B , n int ) {
718
754
if n == 0 {
719
755
b .Skip ("can't access empty map" )
0 commit comments