aboutsummaryrefslogtreecommitdiff
path: root/src/unicode
diff options
context:
space:
mode:
authorMarcel van Lohuizen <mpvl@golang.org>2015-09-09 10:43:06 +0200
committerMarcel van Lohuizen <mpvl@golang.org>2015-10-26 10:42:38 +0000
commit3d198bd7be771ed0722af577eef840b24d62374a (patch)
tree9fca9368694ae3739e8fd8f20b47897c359b2099 /src/unicode
parentadf9b30e55943feb44669ebf773964fd32d4ee94 (diff)
downloadgo-3d198bd7be771ed0722af577eef840b24d62374a.tar.gz
go-3d198bd7be771ed0722af577eef840b24d62374a.zip
unicode/utf8: added benchmarks
Cover some functions that weren't benched before and add InString variants if the underlying implementation is different. Note: compare (Valid|RuneCount)InString* to their (Valid|RuneCount)* counterparts. It shows, somewhat unexpectedly, that ranging over a string is *much* slower than using calls to DecodeRune. Results: In order to avoid a discrepancy in measuring the performance of core we could leave the names of the string-based measurements unchanged and suffix the added alternatives with Bytes. Compared to old: BenchmarkRuneCountTenASCIIChars-8 44.3 12.4 -72.01% BenchmarkRuneCountTenJapaneseChars-8 167 67.1 -59.82% BenchmarkEncodeASCIIRune-8 3.37 3.44 +2.08% BenchmarkEncodeJapaneseRune-8 7.19 7.24 +0.70% BenchmarkDecodeASCIIRune-8 5.41 5.53 +2.22% BenchmarkDecodeJapaneseRune-8 8.17 8.41 +2.94% All benchmarks: BenchmarkRuneCountTenASCIIChars-8 100000000 12.4 ns/op BenchmarkRuneCountTenJapaneseChars-8 20000000 67.1 ns/op BenchmarkRuneCountInStringTenASCIIChars-8 30000000 44.5 ns/op BenchmarkRuneCountInStringTenJapaneseChars-8 10000000 165 ns/op BenchmarkValidTenASCIIChars-8 100000000 12.5 ns/op BenchmarkValidTenJapaneseChars-8 20000000 71.1 ns/op BenchmarkValidStringTenASCIIChars-8 30000000 50.0 ns/op BenchmarkValidStringTenJapaneseChars-8 10000000 161 ns/op BenchmarkEncodeASCIIRune-8 500000000 3.44 ns/op BenchmarkEncodeJapaneseRune-8 200000000 7.24 ns/op BenchmarkDecodeASCIIRune-8 300000000 5.53 ns/op BenchmarkDecodeJapaneseRune-8 200000000 8.41 ns/op BenchmarkFullASCIIRune-8 500000000 3.91 ns/op BenchmarkFullJapaneseRune-8 300000000 4.22 ns/op Change-Id: I674d2ee4917b975a37717bbfa1082cc84dcd275e Reviewed-on: https://go-review.googlesource.com/14431 Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/unicode')
-rw-r--r--src/unicode/utf8/utf8_test.go56
1 files changed, 55 insertions, 1 deletions
diff --git a/src/unicode/utf8/utf8_test.go b/src/unicode/utf8/utf8_test.go
index 758d7a0f8e..36d3959eee 100644
--- a/src/unicode/utf8/utf8_test.go
+++ b/src/unicode/utf8/utf8_test.go
@@ -404,17 +404,57 @@ func TestValidRune(t *testing.T) {
}
func BenchmarkRuneCountTenASCIIChars(b *testing.B) {
+ s := []byte("0123456789")
for i := 0; i < b.N; i++ {
- RuneCountInString("0123456789")
+ RuneCount(s)
}
}
func BenchmarkRuneCountTenJapaneseChars(b *testing.B) {
+ s := []byte("日本語日本語日本語日")
+ for i := 0; i < b.N; i++ {
+ RuneCount(s)
+ }
+}
+
+func BenchmarkRuneCountInStringTenASCIIChars(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ RuneCountInString("0123456789")
+ }
+}
+
+func BenchmarkRuneCountInStringTenJapaneseChars(b *testing.B) {
for i := 0; i < b.N; i++ {
RuneCountInString("日本語日本語日本語日")
}
}
+func BenchmarkValidTenASCIIChars(b *testing.B) {
+ s := []byte("0123456789")
+ for i := 0; i < b.N; i++ {
+ Valid(s)
+ }
+}
+
+func BenchmarkValidTenJapaneseChars(b *testing.B) {
+ s := []byte("日本語日本語日本語日")
+ for i := 0; i < b.N; i++ {
+ Valid(s)
+ }
+}
+
+func BenchmarkValidStringTenASCIIChars(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ ValidString("0123456789")
+ }
+}
+
+func BenchmarkValidStringTenJapaneseChars(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ ValidString("日本語日本語日本語日")
+ }
+}
+
func BenchmarkEncodeASCIIRune(b *testing.B) {
buf := make([]byte, UTFMax)
for i := 0; i < b.N; i++ {
@@ -442,3 +482,17 @@ func BenchmarkDecodeJapaneseRune(b *testing.B) {
DecodeRune(nihon)
}
}
+
+func BenchmarkFullASCIIRune(b *testing.B) {
+ a := []byte{'a'}
+ for i := 0; i < b.N; i++ {
+ FullRune(a)
+ }
+}
+
+func BenchmarkFullJapaneseRune(b *testing.B) {
+ nihon := []byte("本")
+ for i := 0; i < b.N; i++ {
+ FullRune(nihon)
+ }
+}