bench_test.go 1.1 KB

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