diff options
author | Alberto Donizetti <alb.donizetti@gmail.com> | 2016-01-29 21:22:11 +0100 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-02-23 13:58:26 +0000 |
commit | abf4696ede52ebd980605b10034f39af32ac5d90 (patch) | |
tree | 0fd6041e9bcfe3546aae56e925b0ed53bed70a51 /src/unicode | |
parent | 3ec0651539d481100b6e735d54072627276f48d3 (diff) | |
download | go-abf4696ede52ebd980605b10034f39af32ac5d90.tar.gz go-abf4696ede52ebd980605b10034f39af32ac5d90.zip |
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>
Diffstat (limited to 'src/unicode')
-rw-r--r-- | src/unicode/utf16/utf16_test.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/unicode/utf16/utf16_test.go b/src/unicode/utf16/utf16_test.go index 3dca472bbe..e5be504e08 100644 --- a/src/unicode/utf16/utf16_test.go +++ b/src/unicode/utf16/utf16_test.go @@ -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) + } + } +} |