-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsanitize_benchmark_test.go
More file actions
229 lines (196 loc) 路 5.84 KB
/
Copy pathsanitize_benchmark_test.go
File metadata and controls
229 lines (196 loc) 路 5.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
package sanitize_test
import (
"regexp"
"testing"
"github.com/mrz1836/go-sanitize"
)
// BenchmarkAlpha benchmarks the Alpha method
func BenchmarkAlpha(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.Alpha("This is the test string.", false)
}
}
// BenchmarkAlphaNumeric benchmarks the AlphaNumeric method
func BenchmarkAlphaNumeric(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.AlphaNumeric("This is the test string 12345.", false)
}
}
// BenchmarkAlphaNumeric_WithSpaces benchmarks the AlphaNumeric method
func BenchmarkAlphaNumeric_WithSpaces(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.AlphaNumeric("This is the test string 12345.", true)
}
}
// BenchmarkAlpha_WithSpaces benchmarks the Alpha method
func BenchmarkAlpha_WithSpaces(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.Alpha("This is the test string.", true)
}
}
// BenchmarkBitcoinAddress benchmarks the BitcoinAddress method
func BenchmarkBitcoinAddress(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.BitcoinAddress("1K6c7LGpdB8LwoGNVfG51dRV9UUEijbrWs")
}
}
// BenchmarkBitcoinCashAddress benchmarks the BitcoinCashAddress() method
func BenchmarkBitcoinCashAddress(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.BitcoinCashAddress("qze7yy2au5vuznvn8lzj5y0j5t066vhs75e3m0eptz")
}
}
// BenchmarkCustom benchmarks the Custom method
func BenchmarkCustom(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.Custom("This is the test string 12345.", `[^a-zA-Z0-9]`)
}
}
// BenchmarkCustomCompiled benchmarks the CustomCompiled method
func BenchmarkCustomCompiled(b *testing.B) {
re := regexp.MustCompile(`[^a-zA-Z0-9]`)
for i := 0; i < b.N; i++ {
_, _ = sanitize.CustomCompiled("This is the test string 12345.", re)
}
}
// BenchmarkDecimal benchmarks the Decimal method
func BenchmarkDecimal(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.Decimal("String: -123.12345")
}
}
// BenchmarkDomain benchmarks the Domain method
func BenchmarkDomain(b *testing.B) {
for i := 0; i < b.N; i++ {
_, _ = sanitize.Domain("https://Example.COM/?param=value", false, false)
}
}
// BenchmarkDomain_PreserveCase benchmarks the Domain method
func BenchmarkDomain_PreserveCase(b *testing.B) {
for i := 0; i < b.N; i++ {
_, _ = sanitize.Domain("https://Example.COM/?param=value", true, false)
}
}
// BenchmarkDomain_RemoveWww benchmarks the Domain method
func BenchmarkDomain_RemoveWww(b *testing.B) {
for i := 0; i < b.N; i++ {
_, _ = sanitize.Domain("https://Example.COM/?param=value", false, true)
}
}
// BenchmarkEmail benchmarks the Email method
func BenchmarkEmail(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.Email("mailto:Person@Example.COM ", false)
}
}
// BenchmarkEmail_PreserveCase benchmarks the Email method
func BenchmarkEmail_PreserveCase(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.Email("mailto:Person@Example.COM ", true)
}
}
// BenchmarkFirstToUpper benchmarks the FirstToUpper method
func BenchmarkFirstToUpper(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.FirstToUpper("make this upper")
}
}
// BenchmarkFormalName benchmarks the FormalName method
func BenchmarkFormalName(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.FormalName("John McDonald Jr.")
}
}
// BenchmarkHTML benchmarks the HTML method
func BenchmarkHTML(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.HTML("<html><b>Test This!</b></html>")
}
}
// BenchmarkIPAddress benchmarks the IPAddress method
func BenchmarkIPAddress(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.IPAddress(" 192.168.0.1 ")
}
}
// BenchmarkIPAddress_V6 benchmarks the IPAddress method
func BenchmarkIPAddress_IPV6(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.IPAddress(" 2602:305:bceb:1bd0:44ef:fedb:4f8f:da4f ")
}
}
// BenchmarkNumeric benchmarks the numeric method
func BenchmarkNumeric(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.Numeric(" 192.168.0.1 ")
}
}
// BenchmarkPhoneNumber benchmarks the PhoneNumber method
func BenchmarkPhoneNumber(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.PhoneNumber("+1 (234) 567-8900")
}
}
// BenchmarkPathName benchmarks the PathName method
func BenchmarkPathName(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.PathName("/This-Path-Name_Works-/")
}
}
// BenchmarkPunctuation benchmarks the Punctuation method
func BenchmarkPunctuation(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.Punctuation("Does this work? They're doing it?")
}
}
// BenchmarkScientificNotation benchmarks the ScientificNotation method
func BenchmarkScientificNotation(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.ScientificNotation("String: -1.096e-3")
}
}
// BenchmarkScripts benchmarks the Scripts method
func BenchmarkScripts(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.Scripts("<script>$(){ var remove='me'; }</script>")
}
}
// BenchmarkSingleLine benchmarks the SingleLine method
func BenchmarkSingleLine(b *testing.B) {
testString := `This line
That Line
Another Line`
for i := 0; i < b.N; i++ {
_ = sanitize.SingleLine(testString)
}
}
// BenchmarkTime benchmarks the Time method
func BenchmarkTime(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.Time("Time is 05:10:23")
}
}
// BenchmarkURI benchmarks the URI method
func BenchmarkURI(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.URI("/Test/This/Url/?param=value")
}
}
// BenchmarkURL benchmarks the URL method
func BenchmarkURL(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.URL("/Test/This/Url/?param=value")
}
}
// BenchmarkXML benchmarks the XML method
func BenchmarkXML(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.XML("<xml>Test This!</xml>")
}
}
// BenchmarkXSS benchmarks the XSS method
func BenchmarkXSS(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = sanitize.XSS("<script>Test This!</script>")
}
}