Commit b5358e06 authored by Rob Pike's avatar Rob Pike

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
parent 773e7798
......@@ -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)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment