aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/strings/replace_test.go
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2014-06-20 12:18:33 -0700
committerRui Ueyama <ruiu@google.com>2014-06-20 12:18:33 -0700
commit382c461a89bf2ee1ab91ba9c193f5cb7d257246c (patch)
tree99fb1ddaa6dfb279b1be7f49e4ce09a167efe57a /src/pkg/strings/replace_test.go
parent22d46d53ea31b1bcee0a125f6fc1651ae2541563 (diff)
downloadgo-382c461a89bf2ee1ab91ba9c193f5cb7d257246c.tar.xz
strings: speed up byteReplacer.Replace
benchmark old ns/op new ns/op delta BenchmarkByteReplacerWriteString 7359 3661 -50.25% LGTM=dave R=golang-codereviews, dave CC=golang-codereviews https://golang.org/cl/102550043
Diffstat (limited to 'src/pkg/strings/replace_test.go')
-rw-r--r--src/pkg/strings/replace_test.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/pkg/strings/replace_test.go b/src/pkg/strings/replace_test.go
index ca57f08251..2cb318b69d 100644
--- a/src/pkg/strings/replace_test.go
+++ b/src/pkg/strings/replace_test.go
@@ -480,7 +480,7 @@ func BenchmarkHTMLEscapeOld(b *testing.B) {
}
}
-func BenchmarkWriteString(b *testing.B) {
+func BenchmarkByteStringReplacerWriteString(b *testing.B) {
str := Repeat("I <3 to escape HTML & other text too.", 100)
buf := new(bytes.Buffer)
for i := 0; i < b.N; i++ {
@@ -489,6 +489,15 @@ func BenchmarkWriteString(b *testing.B) {
}
}
+func BenchmarkByteReplacerWriteString(b *testing.B) {
+ str := Repeat("abcdefghijklmnopqrstuvwxyz", 100)
+ buf := new(bytes.Buffer)
+ for i := 0; i < b.N; i++ {
+ capitalLetters.WriteString(buf, str)
+ buf.Reset()
+ }
+}
+
// BenchmarkByteByteReplaces compares byteByteImpl against multiple Replaces.
func BenchmarkByteByteReplaces(b *testing.B) {
str := Repeat("a", 100) + Repeat("b", 100)