diff --git a/common/encapsulation/encapsulation_test.go b/common/encapsulation/encapsulation_test.go index 333abb4..27631d0 100644 --- a/common/encapsulation/encapsulation_test.go +++ b/common/encapsulation/encapsulation_test.go @@ -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) + } + } +}