LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package bufio_test | 5 package bufio_test |
6 | 6 |
7 import ( | 7 import ( |
8 . "bufio" | 8 . "bufio" |
9 "bytes" | 9 "bytes" |
10 "errors" | 10 "errors" |
(...skipping 1265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1276 dstBuf := new(bytes.Buffer) | 1276 dstBuf := new(bytes.Buffer) |
1277 dst := onlyWriter{dstBuf} | 1277 dst := onlyWriter{dstBuf} |
1278 for i := 0; i < b.N; i++ { | 1278 for i := 0; i < b.N; i++ { |
1279 srcBuf.Reset() | 1279 srcBuf.Reset() |
1280 src.Reset(srcBuf) | 1280 src.Reset(srcBuf) |
1281 dstBuf.Reset() | 1281 dstBuf.Reset() |
1282 io.Copy(dst, src) | 1282 io.Copy(dst, src) |
1283 } | 1283 } |
1284 } | 1284 } |
1285 | 1285 |
1286 func BenchmarkReaderCopyNonOptimal(b *testing.B) { | 1286 func BenchmarkReaderCopyUnoptimal(b *testing.B) { |
1287 » // Non-optimal case is where the underlying reader doesn't implement io.
WriterTo | 1287 » // Unoptimal case is where the underlying reader doesn't implement io.Wr
iterTo |
1288 srcBuf := bytes.NewBuffer(make([]byte, 8192)) | 1288 srcBuf := bytes.NewBuffer(make([]byte, 8192)) |
1289 src := NewReader(onlyReader{srcBuf}) | 1289 src := NewReader(onlyReader{srcBuf}) |
1290 dstBuf := new(bytes.Buffer) | 1290 dstBuf := new(bytes.Buffer) |
1291 dst := onlyWriter{dstBuf} | 1291 dst := onlyWriter{dstBuf} |
1292 for i := 0; i < b.N; i++ { | 1292 for i := 0; i < b.N; i++ { |
1293 srcBuf.Reset() | 1293 srcBuf.Reset() |
1294 src.Reset(onlyReader{srcBuf}) | 1294 src.Reset(onlyReader{srcBuf}) |
1295 dstBuf.Reset() | 1295 dstBuf.Reset() |
1296 io.Copy(dst, src) | 1296 io.Copy(dst, src) |
1297 } | 1297 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1339 dstBuf := new(bytes.Buffer) | 1339 dstBuf := new(bytes.Buffer) |
1340 dst := NewWriter(dstBuf) | 1340 dst := NewWriter(dstBuf) |
1341 for i := 0; i < b.N; i++ { | 1341 for i := 0; i < b.N; i++ { |
1342 srcBuf.Reset() | 1342 srcBuf.Reset() |
1343 dstBuf.Reset() | 1343 dstBuf.Reset() |
1344 dst.Reset(dstBuf) | 1344 dst.Reset(dstBuf) |
1345 io.Copy(dst, src) | 1345 io.Copy(dst, src) |
1346 } | 1346 } |
1347 } | 1347 } |
1348 | 1348 |
1349 func BenchmarkWriterCopyNonOptimal(b *testing.B) { | 1349 func BenchmarkWriterCopyUnoptimal(b *testing.B) { |
1350 srcBuf := bytes.NewBuffer(make([]byte, 8192)) | 1350 srcBuf := bytes.NewBuffer(make([]byte, 8192)) |
1351 src := onlyReader{srcBuf} | 1351 src := onlyReader{srcBuf} |
1352 dstBuf := new(bytes.Buffer) | 1352 dstBuf := new(bytes.Buffer) |
1353 dst := NewWriter(onlyWriter{dstBuf}) | 1353 dst := NewWriter(onlyWriter{dstBuf}) |
1354 for i := 0; i < b.N; i++ { | 1354 for i := 0; i < b.N; i++ { |
1355 srcBuf.Reset() | 1355 srcBuf.Reset() |
1356 dstBuf.Reset() | 1356 dstBuf.Reset() |
1357 dst.Reset(onlyWriter{dstBuf}) | 1357 dst.Reset(onlyWriter{dstBuf}) |
1358 io.Copy(dst, src) | 1358 io.Copy(dst, src) |
1359 } | 1359 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1408 | 1408 |
1409 func BenchmarkWriterFlush(b *testing.B) { | 1409 func BenchmarkWriterFlush(b *testing.B) { |
1410 b.ReportAllocs() | 1410 b.ReportAllocs() |
1411 bw := NewWriter(ioutil.Discard) | 1411 bw := NewWriter(ioutil.Discard) |
1412 str := strings.Repeat("x", 50) | 1412 str := strings.Repeat("x", 50) |
1413 for i := 0; i < b.N; i++ { | 1413 for i := 0; i < b.N; i++ { |
1414 bw.WriteString(str) | 1414 bw.WriteString(str) |
1415 bw.Flush() | 1415 bw.Flush() |
1416 } | 1416 } |
1417 } | 1417 } |
LEFT | RIGHT |