Skip to content

Commit 4a30663

Browse files
committed
fix wrong benchmark
1 parent 55c502d commit 4a30663

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

internal/proto/peek_push_notification_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,17 @@ func BenchmarkPeekPushNotificationName(b *testing.B) {
370370
buf := createValidPushNotification(tc.notification, "data")
371371
data := buf.Bytes()
372372

373+
// Reuse both bytes.Reader and proto.Reader to avoid allocations
374+
bytesReader := bytes.NewReader(data)
375+
reader := NewReader(bytesReader)
376+
373377
b.ResetTimer()
378+
b.ReportAllocs()
374379
for i := 0; i < b.N; i++ {
375-
reader := NewReader(bytes.NewReader(data))
380+
// Reset the bytes.Reader to the beginning without allocating
381+
bytesReader.Reset(data)
382+
// Reset the proto.Reader to reuse the bufio buffer
383+
reader.Reset(bytesReader)
376384
_, err := reader.PeekPushNotificationName()
377385
if err != nil {
378386
b.Errorf("PeekPushNotificationName should not error: %v", err)

0 commit comments

Comments
 (0)