bytes, strings: optimize Repeat

Call copy with as large buffer as possible to reduce the
number of function calls.

benchmark                 old ns/op    new ns/op    delta
BenchmarkBytesRepeat            540          162  -70.00%
BenchmarkStringsRepeat          563          177  -68.56%

LGTM=josharian
R=golang-codereviews, josharian, dave, dvyukov
CC=golang-codereviews
https://golang.org/cl/90550043
This commit is contained in:
Rui Ueyama 2014-06-11 19:03:59 -07:00 committed by Josh Bleecher Snyder
parent 22a5d2cc96
commit 7bcbb65d78
4 changed files with 20 additions and 6 deletions

View file

@ -1232,3 +1232,9 @@ func BenchmarkTrimSpace(b *testing.B) {
TrimSpace(s)
}
}
func BenchmarkRepeat(b *testing.B) {
for i := 0; i < b.N; i++ {
Repeat([]byte("-"), 80)
}
}