1// 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}
55