mirror of
https://github.com/golang/go
synced 2024-11-26 21:11:57 -07:00
unicode/utf16: add benchmarks
For #6957 Change-Id: Ic497c12f33efc933e9fe81f6cd1b2a0a01abbabf Reviewed-on: https://go-review.googlesource.com/19820 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
3ec0651539
commit
abf4696ede
@ -147,3 +147,56 @@ func TestIsSurrogate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkDecodeValidASCII(b *testing.B) {
|
||||
// "hello world"
|
||||
data := []uint16{104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100}
|
||||
for i := 0; i < b.N; i++ {
|
||||
Decode(data)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkDecodeValidJapaneseChars(b *testing.B) {
|
||||
// "日本語日本語日本語"
|
||||
data := []uint16{26085, 26412, 35486, 26085, 26412, 35486, 26085, 26412, 35486}
|
||||
for i := 0; i < b.N; i++ {
|
||||
Decode(data)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkDecodeRune(b *testing.B) {
|
||||
rs := make([]rune, 10)
|
||||
// U+1D4D0 to U+1D4D4: MATHEMATICAL BOLD SCRIPT CAPITAL LETTERS
|
||||
for i, u := range []rune{'𝓐', '𝓑', '𝓒', '𝓓', '𝓔'} {
|
||||
rs[2*i], rs[2*i+1] = EncodeRune(u)
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for j := 0; j < 5; j++ {
|
||||
DecodeRune(rs[2*j], rs[2*j+1])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEncodeValidASCII(b *testing.B) {
|
||||
data := []rune{'h', 'e', 'l', 'l', 'o'}
|
||||
for i := 0; i < b.N; i++ {
|
||||
Encode(data)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEncodeValidJapaneseChars(b *testing.B) {
|
||||
data := []rune{'日', '本', '語'}
|
||||
for i := 0; i < b.N; i++ {
|
||||
Encode(data)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEncodeRune(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
for _, u := range []rune{'𝓐', '𝓑', '𝓒', '𝓓', '𝓔'} {
|
||||
EncodeRune(u)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user