benchmark_test.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (c) 2018, Psiphon Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. package wildcard
  20. import (
  21. "testing"
  22. "github.com/gobwas/glob"
  23. go_glob "github.com/ryanuber/go-glob"
  24. )
  25. func BenchmarkFixedGlobPrecompile(b *testing.B) {
  26. g := glob.MustCompile(target)
  27. for i := 0; i < b.N; i++ {
  28. if !g.Match(target) {
  29. b.Fatalf("unexpected result")
  30. }
  31. }
  32. }
  33. func BenchmarkPrefixGlobPrecompile(b *testing.B) {
  34. g := glob.MustCompile("Lorem*")
  35. for i := 0; i < b.N; i++ {
  36. if !g.Match(target) {
  37. b.Fatalf("unexpected result")
  38. }
  39. }
  40. }
  41. func BenchmarkSuffixGlobPrecompile(b *testing.B) {
  42. g := glob.MustCompile("*aliqua.")
  43. for i := 0; i < b.N; i++ {
  44. if !g.Match(target) {
  45. b.Fatalf("unexpected result")
  46. }
  47. }
  48. }
  49. func BenchmarkMultipleGlobPrecompile(b *testing.B) {
  50. g := glob.MustCompile("*dolor*eiusmod*magna*")
  51. for i := 0; i < b.N; i++ {
  52. if !g.Match(target) {
  53. b.Fatalf("unexpected result")
  54. }
  55. }
  56. }
  57. func BenchmarkFixedGlob(b *testing.B) {
  58. for i := 0; i < b.N; i++ {
  59. g := glob.MustCompile(target)
  60. if !g.Match(target) {
  61. b.Fatalf("unexpected result")
  62. }
  63. }
  64. }
  65. func BenchmarkPrefixGlob(b *testing.B) {
  66. for i := 0; i < b.N; i++ {
  67. g := glob.MustCompile("Lorem*")
  68. if !g.Match(target) {
  69. b.Fatalf("unexpected result")
  70. }
  71. }
  72. }
  73. func BenchmarkSuffixGlob(b *testing.B) {
  74. for i := 0; i < b.N; i++ {
  75. g := glob.MustCompile("*aliqua.")
  76. if !g.Match(target) {
  77. b.Fatalf("unexpected result")
  78. }
  79. }
  80. }
  81. func BenchmarkMultipleGlob(b *testing.B) {
  82. for i := 0; i < b.N; i++ {
  83. g := glob.MustCompile("*dolor*eiusmod*magna*")
  84. if !g.Match(target) {
  85. b.Fatalf("unexpected result")
  86. }
  87. }
  88. }
  89. func BenchmarkFixedGoGlob(b *testing.B) {
  90. for i := 0; i < b.N; i++ {
  91. if !go_glob.Glob(target, target) {
  92. b.Fatalf("unexpected result")
  93. }
  94. }
  95. }
  96. func BenchmarkPrefixGoGlob(b *testing.B) {
  97. for i := 0; i < b.N; i++ {
  98. if !go_glob.Glob("Lorem*", target) {
  99. b.Fatalf("unexpected result")
  100. }
  101. }
  102. }
  103. func BenchmarkSuffixGoGlob(b *testing.B) {
  104. for i := 0; i < b.N; i++ {
  105. if !go_glob.Glob("*aliqua.", target) {
  106. b.Fatalf("unexpected result")
  107. }
  108. }
  109. }
  110. func BenchmarkMultipleGoGlob(b *testing.B) {
  111. for i := 0; i < b.N; i++ {
  112. if !go_glob.Glob("*dolor*eiusmod*magna*", target) {
  113. b.Fatalf("unexpected result")
  114. }
  115. }
  116. }