Skip to content

Commit e825db8

Browse files
committed
fix benchmark report
1 parent 316aeb7 commit e825db8

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

hset_benchmark_test.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -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

@@ -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

Comments
 (0)