Copied from CL 60630
Current results:
name time/op
CopyNSmall-4 2.20µs ±90%
CopyNLarge-4 136µs ±56%
name alloc/op
CopyNSmall-4 1.84kB ±21%
CopyNLarge-4 128kB ±10%
name allocs/op
CopyNSmall-4 1.00 ± 0%
CopyNLarge-4 1.00 ± 0%
Change-Id: If08c0132a773e936c9f61bff96e0aabf58006d31
Reviewed-on: https://go-review.googlesource.com/64932
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
}
}
+func BenchmarkCopyNSmall(b *testing.B) {
+ bs := bytes.Repeat([]byte{0}, 512+1)
+ rd := bytes.NewReader(bs)
+ buf := new(Buffer)
+ b.ResetTimer()
+
+ for i := 0; i < b.N; i++ {
+ CopyN(buf, rd, 512)
+ rd.Reset(bs)
+ }
+}
+
+func BenchmarkCopyNLarge(b *testing.B) {
+ bs := bytes.Repeat([]byte{0}, (32*1024)+1)
+ rd := bytes.NewReader(bs)
+ buf := new(Buffer)
+ b.ResetTimer()
+
+ for i := 0; i < b.N; i++ {
+ CopyN(buf, rd, 32*1024)
+ rd.Reset(bs)
+ }
+}
+
type noReadFrom struct {
w Writer
}