Skip to content

Commit

Permalink
ringbuf: fix BenchmarkReader
Browse files Browse the repository at this point in the history
Move calls to ResetTimer and ReportAllocs and avoid allocating a
temporary buffer.
  • Loading branch information
lmb committed May 10, 2022
1 parent 454f0e7 commit c80c08d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ringbuf/reader_test.go
Expand Up @@ -224,9 +224,6 @@ func BenchmarkReader(b *testing.B) {
},
}

b.ResetTimer()
b.ReportAllocs()

for _, bm := range readerBenchmarks {
b.Run(bm.name, func(b *testing.B) {
prog, events := mustOutputSamplesProg(b, bm.flags, 80)
Expand All @@ -237,8 +234,13 @@ func BenchmarkReader(b *testing.B) {
}
defer rd.Close()

buf := make([]byte, 14)

b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
ret, _, err := prog.Benchmark(make([]byte, 14), 1, nil)
ret, _, err := prog.Test(buf)
if err != nil {
b.Fatal(err)
} else if errno := syscall.Errno(-int32(ret)); errno != 0 {
Expand Down

0 comments on commit c80c08d

Please sign in to comment.