From d4451362c0fa47b25fc2e69129e68cbbee4a6bdf Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Sat, 4 Mar 2017 16:28:59 -0800 Subject: [PATCH] runtime: add slicebytetostring benchmark Change-Id: I666d2c6ea8d0b54a71260809d1a2573b122865b2 Reviewed-on: https://go-review.googlesource.com/37790 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/runtime/string_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/runtime/string_test.go b/src/runtime/string_test.go index fcfc52291f0..7633cfde046 100644 --- a/src/runtime/string_test.go +++ b/src/runtime/string_test.go @@ -6,6 +6,7 @@ package runtime_test import ( "runtime" + "strconv" "strings" "testing" ) @@ -89,6 +90,20 @@ func BenchmarkConcatStringAndBytes(b *testing.B) { } } +var escapeString string + +func BenchmarkSliceByteToString(b *testing.B) { + buf := []byte{'!'} + for n := 0; n < 8; n++ { + b.Run(strconv.Itoa(len(buf)), func(b *testing.B) { + for i := 0; i < b.N; i++ { + escapeString = string(buf) + } + }) + buf = append(buf, buf...) + } +} + var stringdata = []struct{ name, data string }{ {"ASCII", "01234567890"}, {"Japanese", "日本語日本語日本語"},