github.com/psiphon-labs/psiphon-tunnel-core@v2.0.28+incompatible/psiphon/common/wildcard/benchmark_test.go (about) 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 20 package wildcard 21 22 import ( 23 "testing" 24 25 "github.com/gobwas/glob" 26 go_glob "github.com/ryanuber/go-glob" 27 ) 28 29 func BenchmarkFixedGlobPrecompile(b *testing.B) { 30 g := glob.MustCompile(target) 31 for i := 0; i < b.N; i++ { 32 if !g.Match(target) { 33 b.Fatalf("unexpected result") 34 } 35 } 36 } 37 38 func BenchmarkPrefixGlobPrecompile(b *testing.B) { 39 g := glob.MustCompile("Lorem*") 40 for i := 0; i < b.N; i++ { 41 if !g.Match(target) { 42 b.Fatalf("unexpected result") 43 } 44 } 45 } 46 47 func BenchmarkSuffixGlobPrecompile(b *testing.B) { 48 g := glob.MustCompile("*aliqua.") 49 for i := 0; i < b.N; i++ { 50 if !g.Match(target) { 51 b.Fatalf("unexpected result") 52 } 53 } 54 } 55 56 func BenchmarkMultipleGlobPrecompile(b *testing.B) { 57 g := glob.MustCompile("*dolor*eiusmod*magna*") 58 for i := 0; i < b.N; i++ { 59 if !g.Match(target) { 60 b.Fatalf("unexpected result") 61 } 62 } 63 } 64 65 func BenchmarkFixedGlob(b *testing.B) { 66 for i := 0; i < b.N; i++ { 67 g := glob.MustCompile(target) 68 if !g.Match(target) { 69 b.Fatalf("unexpected result") 70 } 71 } 72 } 73 74 func BenchmarkPrefixGlob(b *testing.B) { 75 for i := 0; i < b.N; i++ { 76 g := glob.MustCompile("Lorem*") 77 if !g.Match(target) { 78 b.Fatalf("unexpected result") 79 } 80 } 81 } 82 83 func BenchmarkSuffixGlob(b *testing.B) { 84 for i := 0; i < b.N; i++ { 85 g := glob.MustCompile("*aliqua.") 86 if !g.Match(target) { 87 b.Fatalf("unexpected result") 88 } 89 } 90 } 91 92 func BenchmarkMultipleGlob(b *testing.B) { 93 for i := 0; i < b.N; i++ { 94 g := glob.MustCompile("*dolor*eiusmod*magna*") 95 if !g.Match(target) { 96 b.Fatalf("unexpected result") 97 } 98 } 99 } 100 101 func BenchmarkFixedGoGlob(b *testing.B) { 102 for i := 0; i < b.N; i++ { 103 if !go_glob.Glob(target, target) { 104 b.Fatalf("unexpected result") 105 } 106 } 107 } 108 109 func BenchmarkPrefixGoGlob(b *testing.B) { 110 for i := 0; i < b.N; i++ { 111 if !go_glob.Glob("Lorem*", target) { 112 b.Fatalf("unexpected result") 113 } 114 } 115 } 116 117 func BenchmarkSuffixGoGlob(b *testing.B) { 118 for i := 0; i < b.N; i++ { 119 if !go_glob.Glob("*aliqua.", target) { 120 b.Fatalf("unexpected result") 121 } 122 } 123 } 124 125 func BenchmarkMultipleGoGlob(b *testing.B) { 126 for i := 0; i < b.N; i++ { 127 if !go_glob.Glob("*dolor*eiusmod*magna*", target) { 128 b.Fatalf("unexpected result") 129 } 130 } 131 }