Permalink
Browse files

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: Ian Lance Taylor <iant@golang.org>
  • Loading branch information...
bogem authored and ianlancetaylor committed Sep 20, 2017
1 parent 098eb01 commit 36e1c7ab73591388ba1a7246ada21e0baefd2ce1
Showing with 24 additions and 0 deletions.
  1. +24 −0 src/io/io_test.go
View
@@ -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 {
w Writer
}

0 comments on commit 36e1c7a

Please sign in to comment.