]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add slicebytetostring benchmark
authorJosh Bleecher Snyder <josharian@gmail.com>
Sun, 5 Mar 2017 00:28:59 +0000 (16:28 -0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Sun, 5 Mar 2017 05:14:08 +0000 (05:14 +0000)
Change-Id: I666d2c6ea8d0b54a71260809d1a2573b122865b2
Reviewed-on: https://go-review.googlesource.com/37790
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/runtime/string_test.go

index fcfc52291f0b02fb887913f27bfec7c8cccf0743..7633cfde0468a237df3ed35983554704cf97ec1b 100644 (file)
@@ -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", "日本語日本語日本語"},