File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments