@@ -10,7 +10,7 @@ import (
1010 "github.com/cornelk/hashmap"
1111)
1212
13- const benchmarkItemCount = 512
13+ const benchmarkItemCount = 1024
1414
1515func setupHashMap (b * testing.B ) * hashmap.HashMap [uintptr , uintptr ] {
1616 b .Helper ()
@@ -19,8 +19,6 @@ func setupHashMap(b *testing.B) *hashmap.HashMap[uintptr, uintptr] {
1919 for i := uintptr (0 ); i < benchmarkItemCount ; i ++ {
2020 m .Set (i , i )
2121 }
22-
23- b .ResetTimer ()
2422 return m
2523}
2624
@@ -45,7 +43,6 @@ func setupHashMapString(b *testing.B) (*hashmap.HashMap[string, string], []strin
4543 keys [i ] = s
4644 }
4745
48- b .ResetTimer ()
4946 return m , keys
5047}
5148
@@ -57,7 +54,6 @@ func setupGoMap(b *testing.B) map[uintptr]uintptr {
5754 m [i ] = i
5855 }
5956
60- b .ResetTimer ()
6157 return m
6258}
6359
@@ -69,7 +65,6 @@ func setupGoSyncMap(b *testing.B) *sync.Map {
6965 m .Store (i , i )
7066 }
7167
72- b .ResetTimer ()
7368 return m
7469}
7570
@@ -83,12 +78,12 @@ func setupGoMapString(b *testing.B) (map[string]string, []string) {
8378 m [s ] = s
8479 keys [i ] = s
8580 }
86- b .ResetTimer ()
8781 return m , keys
8882}
8983
9084func BenchmarkReadHashMapUint (b * testing.B ) {
9185 m := setupHashMap (b )
86+ b .ResetTimer ()
9287
9388 b .RunParallel (func (pb * testing.PB ) {
9489 for pb .Next () {
@@ -105,6 +100,7 @@ func BenchmarkReadHashMapUint(b *testing.B) {
105100func BenchmarkReadHashMapWithWritesUint (b * testing.B ) {
106101 m := setupHashMap (b )
107102 var writer uintptr
103+ b .ResetTimer ()
108104
109105 b .RunParallel (func (pb * testing.PB ) {
110106 // use 1 thread as writer
@@ -129,6 +125,7 @@ func BenchmarkReadHashMapWithWritesUint(b *testing.B) {
129125
130126func BenchmarkReadHashMapString (b * testing.B ) {
131127 m , keys := setupHashMapString (b )
128+ b .ResetTimer ()
132129
133130 b .RunParallel (func (pb * testing.PB ) {
134131 for pb .Next () {
@@ -145,6 +142,7 @@ func BenchmarkReadHashMapString(b *testing.B) {
145142
146143func BenchmarkReadHashMapInterface (b * testing.B ) {
147144 m := setupHashMap (b )
145+ b .ResetTimer ()
148146
149147 b .RunParallel (func (pb * testing.PB ) {
150148 for pb .Next () {
@@ -160,6 +158,7 @@ func BenchmarkReadHashMapInterface(b *testing.B) {
160158
161159func BenchmarkReadHaxMapUint (b * testing.B ) {
162160 m := setupHaxMap (b )
161+ b .ResetTimer ()
163162
164163 b .RunParallel (func (pb * testing.PB ) {
165164 for pb .Next () {
@@ -176,6 +175,7 @@ func BenchmarkReadHaxMapUint(b *testing.B) {
176175func BenchmarkReadHaxMapWithWritesUint (b * testing.B ) {
177176 m := setupHaxMap (b )
178177 var writer uintptr
178+ b .ResetTimer ()
179179
180180 b .RunParallel (func (pb * testing.PB ) {
181181 // use 1 thread as writer
@@ -200,6 +200,7 @@ func BenchmarkReadHaxMapWithWritesUint(b *testing.B) {
200200
201201func BenchmarkReadGoMapUintUnsafe (b * testing.B ) {
202202 m := setupGoMap (b )
203+ b .ResetTimer ()
203204 b .RunParallel (func (pb * testing.PB ) {
204205 for pb .Next () {
205206 for i := uintptr (0 ); i < benchmarkItemCount ; i ++ {
@@ -215,6 +216,7 @@ func BenchmarkReadGoMapUintUnsafe(b *testing.B) {
215216func BenchmarkReadGoMapUintMutex (b * testing.B ) {
216217 m := setupGoMap (b )
217218 l := & sync.RWMutex {}
219+ b .ResetTimer ()
218220 b .RunParallel (func (pb * testing.PB ) {
219221 for pb .Next () {
220222 for i := uintptr (0 ); i < benchmarkItemCount ; i ++ {
@@ -233,6 +235,7 @@ func BenchmarkReadGoMapWithWritesUintMutex(b *testing.B) {
233235 m := setupGoMap (b )
234236 l := & sync.RWMutex {}
235237 var writer uintptr
238+ b .ResetTimer ()
236239
237240 b .RunParallel (func (pb * testing.PB ) {
238241 // use 1 thread as writer
@@ -261,6 +264,7 @@ func BenchmarkReadGoMapWithWritesUintMutex(b *testing.B) {
261264
262265func BenchmarkReadGoSyncMapUint (b * testing.B ) {
263266 m := setupGoSyncMap (b )
267+ b .ResetTimer ()
264268 b .RunParallel (func (pb * testing.PB ) {
265269 for pb .Next () {
266270 for i := uintptr (0 ); i < benchmarkItemCount ; i ++ {
@@ -276,6 +280,7 @@ func BenchmarkReadGoSyncMapUint(b *testing.B) {
276280func BenchmarkReadGoSyncMapWithWritesUint (b * testing.B ) {
277281 m := setupGoSyncMap (b )
278282 var writer uintptr
283+ b .ResetTimer ()
279284
280285 b .RunParallel (func (pb * testing.PB ) {
281286 // use 1 thread as writer
@@ -300,6 +305,7 @@ func BenchmarkReadGoSyncMapWithWritesUint(b *testing.B) {
300305
301306func BenchmarkReadGoMapStringUnsafe (b * testing.B ) {
302307 m , keys := setupGoMapString (b )
308+ b .ResetTimer ()
303309 b .RunParallel (func (pb * testing.PB ) {
304310 for pb .Next () {
305311 for i := 0 ; i < benchmarkItemCount ; i ++ {
@@ -316,6 +322,7 @@ func BenchmarkReadGoMapStringUnsafe(b *testing.B) {
316322func BenchmarkReadGoMapStringMutex (b * testing.B ) {
317323 m , keys := setupGoMapString (b )
318324 l := & sync.RWMutex {}
325+ b .ResetTimer ()
319326 b .RunParallel (func (pb * testing.PB ) {
320327 for pb .Next () {
321328 for i := 0 ; i < benchmarkItemCount ; i ++ {
@@ -333,6 +340,7 @@ func BenchmarkReadGoMapStringMutex(b *testing.B) {
333340
334341func BenchmarkWriteHashMapUint (b * testing.B ) {
335342 m := hashmap .New [uintptr , uintptr ]()
343+ b .ResetTimer ()
336344
337345 for n := 0 ; n < b .N ; n ++ {
338346 for i := uintptr (0 ); i < benchmarkItemCount ; i ++ {
@@ -344,6 +352,7 @@ func BenchmarkWriteHashMapUint(b *testing.B) {
344352func BenchmarkWriteGoMapMutexUint (b * testing.B ) {
345353 m := make (map [uintptr ]uintptr )
346354 l := & sync.RWMutex {}
355+ b .ResetTimer ()
347356
348357 for n := 0 ; n < b .N ; n ++ {
349358 for i := uintptr (0 ); i < benchmarkItemCount ; i ++ {
@@ -356,6 +365,7 @@ func BenchmarkWriteGoMapMutexUint(b *testing.B) {
356365
357366func BenchmarkWriteGoSyncMapUint (b * testing.B ) {
358367 m := & sync.Map {}
368+ b .ResetTimer ()
359369
360370 for n := 0 ; n < b .N ; n ++ {
361371 for i := uintptr (0 ); i < benchmarkItemCount ; i ++ {
0 commit comments