| 887 | } |
| 888 | |
| 889 | func BenchmarkReaderCopyOptimal(b *testing.B) { |
| 890 | // Optimal case is where the underlying reader implements io.WriterTo |
| 891 | srcBuf := bytes.NewBuffer(make([]byte, 8192)) |
| 892 | src := NewReader(srcBuf) |
| 893 | dstBuf := new(bytes.Buffer) |
| 894 | dst := onlyWriter{dstBuf} |
| 895 | for i := 0; i < b.N; i++ { |
| 896 | srcBuf.Reset() |
| 897 | src.Reset(srcBuf) |
| 898 | dstBuf.Reset() |
| 899 | _, _ = io.Copy(dst, src) |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | func BenchmarkReaderCopyUnoptimal(b *testing.B) { |
| 904 | // Unoptimal case is where the underlying reader doesn't implement io.WriterTo |