1
0
mirror of https://github.com/golang/go synced 2024-11-23 17:40:03 -07:00

runtime: add slicebytetostring benchmark

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>
This commit is contained in:
Josh Bleecher Snyder 2017-03-04 16:28:59 -08:00
parent 57e038615d
commit d4451362c0

View 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", "日本語日本語日本語"},