1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 "golang.org/x/text/internal/testtext"
15 var benchData = []struct{ name, str string }{
16 {"ASCII", "Malvolio"},
17 {"NotNormalized", "abcdefg\u0301\u031f"},
19 {"Hangul", "동일조건변경허락"},
22 var benchProfiles = []struct {
26 {"FreeForm", NewFreeform()},
27 {"Nickname", Nickname},
28 {"OpaqueString", OpaqueString},
29 {"UsernameCaseMapped", UsernameCaseMapped},
30 {"UsernameCasePreserved", UsernameCasePreserved},
33 func doBench(b *testing.B, f func(b *testing.B, p *Profile, s string)) {
34 for _, bp := range benchProfiles {
35 for _, d := range benchData {
36 testtext.Bench(b, bp.name+"/"+d.name, func(b *testing.B) {
43 func BenchmarkString(b *testing.B) {
44 doBench(b, func(b *testing.B, p *Profile, s string) {
45 for i := 0; i < b.N; i++ {
51 func BenchmarkBytes(b *testing.B) {
52 doBench(b, func(b *testing.B, p *Profile, s string) {
55 for i := 0; i < b.N; i++ {
61 func BenchmarkAppend(b *testing.B) {
62 doBench(b, func(b *testing.B, p *Profile, s string) {
64 dst := make([]byte, 0, 4096)
66 for i := 0; i < b.N; i++ {
72 func BenchmarkTransform(b *testing.B) {
73 doBench(b, func(b *testing.B, p *Profile, s string) {
75 dst := make([]byte, 2*len(s))
76 t := p.NewTransformer()
78 for i := 0; i < b.N; i++ {
79 t.Transform(dst, src, true)