Benchmark for encapsulation.ReadData.

This commit is contained in:
David Fifield 2022-09-22 17:09:07 -06:00
parent a579c969e6
commit e851861e68

View file

@ -328,3 +328,23 @@ func TestMaxDataForSize(t *testing.T) {
} }
} }
} }
// Benchmark the ReadData function when reading from a stream of data packets of
// different sizes.
func BenchmarkReadData(b *testing.B) {
pr, pw := io.Pipe()
go func() {
for {
for length := 0; length < 128; length++ {
WriteData(pw, paddingBuffer[:length])
}
}
}()
for i := 0; i < b.N; i++ {
_, err := ReadData(pr)
if err != nil {
b.Fatal(err)
}
}
}