LEFT | RIGHT |
(no file at all) | |
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 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 | 1076 |
1077 func BenchmarkWriterCopyNoReadFrom(b *testing.B) { | 1077 func BenchmarkWriterCopyNoReadFrom(b *testing.B) { |
1078 for i := 0; i < b.N; i++ { | 1078 for i := 0; i < b.N; i++ { |
1079 b.StopTimer() | 1079 b.StopTimer() |
1080 src := onlyReader{bytes.NewBuffer(make([]byte, 8192))} | 1080 src := onlyReader{bytes.NewBuffer(make([]byte, 8192))} |
1081 dst := onlyWriter{NewWriter(new(bytes.Buffer))} | 1081 dst := onlyWriter{NewWriter(new(bytes.Buffer))} |
1082 b.StartTimer() | 1082 b.StartTimer() |
1083 io.Copy(dst, src) | 1083 io.Copy(dst, src) |
1084 } | 1084 } |
1085 } | 1085 } |
| 1086 |
| 1087 func BenchmarkReaderEmpty(b *testing.B) { |
| 1088 b.ReportAllocs() |
| 1089 str := strings.Repeat("x", 16<<10) |
| 1090 for i := 0; i < b.N; i++ { |
| 1091 br := NewReader(strings.NewReader(str)) |
| 1092 n, err := io.Copy(ioutil.Discard, br) |
| 1093 if err != nil { |
| 1094 b.Fatal(err) |
| 1095 } |
| 1096 if n != int64(len(str)) { |
| 1097 b.Fatal("wrong length") |
| 1098 } |
| 1099 } |
| 1100 } |
LEFT | RIGHT |