mirror of
https://github.com/golang/go
synced 2024-11-11 22:20:22 -07:00
a few utf8 benchmarks. on my mac:
utf8_test.BenchmarkRuneCountTenASCIIChars 20000000 108 ns/op utf8_test.BenchmarkRuneCountTenJapaneseChars 10000000 199 ns/op utf8_test.BenchmarkEncodeASCIIRune 500000000 6 ns/op utf8_test.BenchmarkEncodeJapaneseRune 100000000 10 ns/op utf8_test.BenchmarkDecodeASCIIRune 100000000 13 ns/op utf8_test.BenchmarkDecodeJapaneseRune 100000000 21 ns/op R=gri CC=golang-dev https://golang.org/cl/161049
This commit is contained in:
parent
773e77981d
commit
b5358e0630
@ -167,3 +167,43 @@ func TestRuneCount(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkRuneCountTenASCIIChars(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
RuneCountInString("0123456789")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkRuneCountTenJapaneseChars(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
RuneCountInString("日本語日本語日本語日")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEncodeASCIIRune(b *testing.B) {
|
||||
buf := make([]byte, UTFMax);
|
||||
for i := 0; i < b.N; i++ {
|
||||
EncodeRune('a', buf)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEncodeJapaneseRune(b *testing.B) {
|
||||
buf := make([]byte, UTFMax);
|
||||
for i := 0; i < b.N; i++ {
|
||||
EncodeRune('本', buf)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkDecodeASCIIRune(b *testing.B) {
|
||||
a := []byte{'a'};
|
||||
for i := 0; i < b.N; i++ {
|
||||
DecodeRune(a)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkDecodeJapaneseRune(b *testing.B) {
|
||||
nihon := strings.Bytes("本");
|
||||
for i := 0; i < b.N; i++ {
|
||||
DecodeRune(nihon)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user