Commit d673c95d authored by Marcel van Lohuizen's avatar Marcel van Lohuizen

exp/norm: Added some benchmarks for form-specific performance measurements.

R=r
CC=golang-dev
https://golang.org/cl/5605051
parent df7f34dd
...@@ -495,11 +495,11 @@ func TestAppend(t *testing.T) { ...@@ -495,11 +495,11 @@ func TestAppend(t *testing.T) {
runAppendTests(t, "TestString", NFKC, stringF, appendTests) runAppendTests(t, "TestString", NFKC, stringF, appendTests)
} }
func doFormBenchmark(b *testing.B, f Form, s string) { func doFormBenchmark(b *testing.B, inf, f Form, s string) {
b.StopTimer() b.StopTimer()
in := []byte(s) in := inf.Bytes([]byte(s))
buf := make([]byte, 2*len(in)) buf := make([]byte, 2*len(in))
b.SetBytes(int64(len(s))) b.SetBytes(int64(len(in)))
b.StartTimer() b.StartTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
buf = f.Append(buf[0:0], in...) buf = f.Append(buf[0:0], in...)
...@@ -510,16 +510,43 @@ func doFormBenchmark(b *testing.B, f Form, s string) { ...@@ -510,16 +510,43 @@ func doFormBenchmark(b *testing.B, f Form, s string) {
var ascii = strings.Repeat("There is nothing to change here! ", 500) var ascii = strings.Repeat("There is nothing to change here! ", 500)
func BenchmarkNormalizeAsciiNFC(b *testing.B) { func BenchmarkNormalizeAsciiNFC(b *testing.B) {
doFormBenchmark(b, NFC, ascii) doFormBenchmark(b, NFC, NFC, ascii)
} }
func BenchmarkNormalizeAsciiNFD(b *testing.B) { func BenchmarkNormalizeAsciiNFD(b *testing.B) {
doFormBenchmark(b, NFD, ascii) doFormBenchmark(b, NFC, NFD, ascii)
} }
func BenchmarkNormalizeAsciiNFKC(b *testing.B) { func BenchmarkNormalizeAsciiNFKC(b *testing.B) {
doFormBenchmark(b, NFKC, ascii) doFormBenchmark(b, NFC, NFKC, ascii)
} }
func BenchmarkNormalizeAsciiNFKD(b *testing.B) { func BenchmarkNormalizeAsciiNFKD(b *testing.B) {
doFormBenchmark(b, NFKD, ascii) doFormBenchmark(b, NFC, NFKD, ascii)
}
func BenchmarkNormalizeNFC2NFC(b *testing.B) {
doFormBenchmark(b, NFC, NFC, txt_all)
}
func BenchmarkNormalizeNFC2NFD(b *testing.B) {
doFormBenchmark(b, NFC, NFD, txt_all)
}
func BenchmarkNormalizeNFD2NFC(b *testing.B) {
doFormBenchmark(b, NFD, NFC, txt_all)
}
func BenchmarkNormalizeNFD2NFD(b *testing.B) {
doFormBenchmark(b, NFD, NFD, txt_all)
}
// Hangul is often special-cased, so we test it separately.
func BenchmarkNormalizeHangulNFC2NFC(b *testing.B) {
doFormBenchmark(b, NFC, NFC, txt_kr)
}
func BenchmarkNormalizeHangulNFC2NFD(b *testing.B) {
doFormBenchmark(b, NFC, NFD, txt_kr)
}
func BenchmarkNormalizeHangulNFD2NFC(b *testing.B) {
doFormBenchmark(b, NFD, NFC, txt_kr)
}
func BenchmarkNormalizeHangulNFD2NFD(b *testing.B) {
doFormBenchmark(b, NFD, NFD, txt_kr)
} }
func doTextBenchmark(b *testing.B, s string) { func doTextBenchmark(b *testing.B, s string) {
...@@ -657,3 +684,6 @@ const txt_cn = `您可以自由: 复制、发行、展览、表演、放映、 ...@@ -657,3 +684,6 @@ const txt_cn = `您可以自由: 复制、发行、展览、表演、放映、
署名 — 您必须按照作者或者许可人指定的方式对作品进行署名。 署名 — 您必须按照作者或者许可人指定的方式对作品进行署名。
相同方式共享 — 如果您改变、转换本作品或者以本作品为基础进行创作, 相同方式共享 — 如果您改变、转换本作品或者以本作品为基础进行创作,
您只能采用与本协议相同的许可协议发布基于本作品的演绎作品。` 您只能采用与本协议相同的许可协议发布基于本作品的演绎作品。`
const txt_cjk = txt_cn + txt_jp + txt_kr
const txt_all = txt_vn + twoByteUtf8 + threeByteUtf8 + txt_cjk
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