You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

55 lines
1.1 KiB

  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. }