From 7bcbb65d7879f17b185cee9ab4ab392da0bd865f Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 11 Jun 2014 19:03:59 -0700 Subject: 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 --- src/pkg/bytes/bytes_test.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/pkg/bytes/bytes_test.go') diff --git a/src/pkg/bytes/bytes_test.go b/src/pkg/bytes/bytes_test.go index 394dd7a443..980c41d754 100644 --- a/src/pkg/bytes/bytes_test.go +++ b/src/pkg/bytes/bytes_test.go @@ -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) + } +} -- cgit v1.3-5-g9baa