Beispiel #1
0
// From Issue 5154.
func BenchmarkBufferNotEmptyWriteRead(b *testing.B) {
	buf := make([]byte, 1024)
	for i := 0; i < b.N; i++ {
		var b Buffer
		b.Write(buf[0:1])
		for i := 0; i < 5<<10; i++ {
			b.Write(buf)
			b.Read(buf)
		}
	}
}
Beispiel #2
0
func BenchmarkBufio(b *testing.B) {
	var scratch [1024]byte
	for i := 0; i < b.N; i++ {
		a := bytes.NewBuffer(bytes.Repeat([]byte("a"), 10240))
		b := bufio.NewReader(a)
		b.Peek(4)
		b.Read(scratch[:])
		b.Read(scratch[:])
		b.Read(scratch[:])
		b.Read(scratch[:])
	}
}
Beispiel #3
0
// Check that we don't compact too often. From Issue 5154.
func BenchmarkBufferFullSmallReads(b *testing.B) {
	buf := make([]byte, 1024)
	for i := 0; i < b.N; i++ {
		var b Buffer
		b.Write(buf)
		for b.Len()+20 < b.Cap() {
			b.Write(buf[:10])
		}
		for i := 0; i < 5<<10; i++ {
			b.Read(buf[:1])
			b.Write(buf[:1])
		}
	}
}