blob: 2db922bfdc7778b21f59773cc3833a69acec973d [file] [log] [blame]
David K. Bainbridge215e0242017-09-05 23:18:24 -07001// Copyright 2016 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.
4
5package bidirule
6
7import (
8 "testing"
9
10 "golang.org/x/text/internal/testtext"
11)
12
13var benchData = []struct{ name, data string }{
14 {"ascii", "Scheveningen"},
15 {"arabic", "دبي"},
16 {"hangul", "다음과"},
17}
18
19func doBench(b *testing.B, fn func(b *testing.B, data string)) {
20 for _, d := range benchData {
21 testtext.Bench(b, d.name, func(b *testing.B) { fn(b, d.data) })
22 }
23}
24
25func BenchmarkSpan(b *testing.B) {
26 r := New()
27 doBench(b, func(b *testing.B, str string) {
28 b.SetBytes(int64(len(str)))
29 data := []byte(str)
30 for i := 0; i < b.N; i++ {
31 r.Reset()
32 r.Span(data, true)
33 }
34 })
35}
36
37func BenchmarkDirectionASCII(b *testing.B) {
38 doBench(b, func(b *testing.B, str string) {
39 b.SetBytes(int64(len(str)))
40 data := []byte(str)
41 for i := 0; i < b.N; i++ {
42 Direction(data)
43 }
44 })
45}
46
47func BenchmarkDirectionStringASCII(b *testing.B) {
48 doBench(b, func(b *testing.B, str string) {
49 b.SetBytes(int64(len(str)))
50 for i := 0; i < b.N; i++ {
51 DirectionString(str)
52 }
53 })
54}