Commit 90103c55 authored by David Fifield's avatar David Fifield
Browse files

Benchmark for encapsulation.ReadData.

parent 222ef10c
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -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)
		}
	}
}