Commit 36e1c7ab authored by Albert Nigmatzianov's avatar Albert Nigmatzianov Committed by Ian Lance Taylor

io: Add benchmarks for CopyN

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: 's avatarIan Lance Taylor <iant@golang.org>
parent 098eb016
...@@ -156,6 +156,30 @@ func TestCopyNWriteTo(t *testing.T) { ...@@ -156,6 +156,30 @@ func TestCopyNWriteTo(t *testing.T) {
} }
} }
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 { type noReadFrom struct {
w Writer w Writer
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment