From 4a3066384bf6d8e291ff3eaaed06afd7aa1f1e75 Mon Sep 17 00:00:00 2001 From: Nedyalko Dyakov Date: Mon, 27 Oct 2025 07:46:00 +0200 Subject: [PATCH] fix wrong benchmark --- internal/proto/peek_push_notification_test.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/proto/peek_push_notification_test.go b/internal/proto/peek_push_notification_test.go index 58a794b8..49186759 100644 --- a/internal/proto/peek_push_notification_test.go +++ b/internal/proto/peek_push_notification_test.go @@ -370,9 +370,17 @@ func BenchmarkPeekPushNotificationName(b *testing.B) { buf := createValidPushNotification(tc.notification, "data") data := buf.Bytes() + // Reuse both bytes.Reader and proto.Reader to avoid allocations + bytesReader := bytes.NewReader(data) + reader := NewReader(bytesReader) + b.ResetTimer() + b.ReportAllocs() 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() if err != nil { b.Errorf("PeekPushNotificationName should not error: %v", err)