1
0
mirror of https://github.com/redis/go-redis.git synced 2025-12-02 06:22:31 +03:00

fix wrong benchmark

This commit is contained in:
Nedyalko Dyakov
2025-10-27 07:46:00 +02:00
parent 55c502dde4
commit 4a3066384b

View File

@@ -370,9 +370,17 @@ func BenchmarkPeekPushNotificationName(b *testing.B) {
buf := createValidPushNotification(tc.notification, "data") buf := createValidPushNotification(tc.notification, "data")
data := buf.Bytes() data := buf.Bytes()
// Reuse both bytes.Reader and proto.Reader to avoid allocations
bytesReader := bytes.NewReader(data)
reader := NewReader(bytesReader)
b.ResetTimer() b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
reader := NewReader(bytes.NewReader(data)) // Reset the bytes.Reader to the beginning without allocating
bytesReader.Reset(data)
// Reset the proto.Reader to reuse the bufio buffer
reader.Reset(bytesReader)
_, err := reader.PeekPushNotificationName() _, err := reader.PeekPushNotificationName()
if err != nil { if err != nil {
b.Errorf("PeekPushNotificationName should not error: %v", err) b.Errorf("PeekPushNotificationName should not error: %v", err)