mirror of
https://github.com/golang/go
synced 2024-11-12 06:30:21 -07:00
exp/norm: Added some benchmarks for form-specific performance measurements.
R=r CC=golang-dev https://golang.org/cl/5605051
This commit is contained in:
parent
df7f34dd2b
commit
d673c95d6c
@ -495,11 +495,11 @@ func TestAppend(t *testing.T) {
|
||||
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()
|
||||
in := []byte(s)
|
||||
in := inf.Bytes([]byte(s))
|
||||
buf := make([]byte, 2*len(in))
|
||||
b.SetBytes(int64(len(s)))
|
||||
b.SetBytes(int64(len(in)))
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
buf = f.Append(buf[0:0], in...)
|
||||
@ -510,16 +510,43 @@ func doFormBenchmark(b *testing.B, f Form, s string) {
|
||||
var ascii = strings.Repeat("There is nothing to change here! ", 500)
|
||||
|
||||
func BenchmarkNormalizeAsciiNFC(b *testing.B) {
|
||||
doFormBenchmark(b, NFC, ascii)
|
||||
doFormBenchmark(b, NFC, NFC, ascii)
|
||||
}
|
||||
func BenchmarkNormalizeAsciiNFD(b *testing.B) {
|
||||
doFormBenchmark(b, NFD, ascii)
|
||||
doFormBenchmark(b, NFC, NFD, ascii)
|
||||
}
|
||||
func BenchmarkNormalizeAsciiNFKC(b *testing.B) {
|
||||
doFormBenchmark(b, NFKC, ascii)
|
||||
doFormBenchmark(b, NFC, NFKC, ascii)
|
||||
}
|
||||
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) {
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user