@@ -101,7 +101,11 @@ func benchmarkHSETOperations(b *testing.B, rdb *redis.Client, ctx context.Contex
101101 avgTimePerOp := b .Elapsed ().Nanoseconds () / int64 (operations * b .N )
102102 b .ReportMetric (float64 (avgTimePerOp ), "ns/op" )
103103 // report average time in milliseconds from totalTimes
104- avgTimePerOpMs := totalTimes [0 ].Milliseconds () / int64 (len (totalTimes ))
104+ sumTime := time .Duration (0 )
105+ for _ , t := range totalTimes {
106+ sumTime += t
107+ }
108+ avgTimePerOpMs := sumTime .Milliseconds () / int64 (len (totalTimes ))
105109 b .ReportMetric (float64 (avgTimePerOpMs ), "ms" )
106110}
107111
@@ -135,7 +139,7 @@ func benchmarkHSETOperationsConcurrent(b *testing.B, rdb *redis.Client, ctx cont
135139 if err != nil {
136140 b .Fatalf ("HSET operation failed: %v" , err )
137141 }
138- timesCh <- time.Since (startTime ))
142+ timesCh <- time .Since (startTime )
139143 }(j )
140144 wg .Wait ()
141145 close (timesCh )
@@ -156,7 +160,12 @@ func benchmarkHSETOperationsConcurrent(b *testing.B, rdb *redis.Client, ctx cont
156160 avgTimePerOp := b .Elapsed ().Nanoseconds () / int64 (operations * b .N )
157161 b .ReportMetric (float64 (avgTimePerOp ), "ns/op" )
158162 // report average time in milliseconds from totalTimes
159- avgTimePerOpMs := totalTimes [0 ].Milliseconds () / int64 (len (totalTimes ))
163+
164+ sumTime := time .Duration (0 )
165+ for _ , t := range totalTimes {
166+ sumTime += t
167+ }
168+ avgTimePerOpMs := sumTime .Milliseconds () / int64 (len (totalTimes ))
160169 b .ReportMetric (float64 (avgTimePerOpMs ), "ms" )
161170}
162171
@@ -195,8 +204,8 @@ func BenchmarkHSET_Concurrent(b *testing.B) {
195204
196205 // Setup Redis client
197206 rdb := redis .NewClient (& redis.Options {
198- Addr : "localhost:6379" ,
199- DB : 0 ,
207+ Addr : "localhost:6379" ,
208+ DB : 0 ,
200209 PoolSize : 1000 ,
201210 })
202211 defer rdb .Close ()
@@ -263,7 +272,11 @@ func benchmarkHSETPipelined(b *testing.B, rdb *redis.Client, ctx context.Context
263272 avgTimePerOp := b .Elapsed ().Nanoseconds () / int64 (operations * b .N )
264273 b .ReportMetric (float64 (avgTimePerOp ), "ns/op" )
265274 // report average time in milliseconds from totalTimes
266- avgTimePerOpMs := totalTimes [0 ].Milliseconds () / int64 (len (totalTimes ))
275+ sumTime := time .Duration (0 )
276+ for _ , t := range totalTimes {
277+ sumTime += t
278+ }
279+ avgTimePerOpMs := sumTime .Milliseconds () / int64 (len (totalTimes ))
267280 b .ReportMetric (float64 (avgTimePerOpMs ), "ms" )
268281}
269282
0 commit comments