-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathURLRegex.swift
43 lines (40 loc) · 1.26 KB
/
URLRegex.swift
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
import _StringProcessing
extension BenchmarkRunner {
mutating func addURLWithWordBoundaries() {
let urlRegex = #"https?://([-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6})\b[-a-zA-Z0-9()@:%_+.~#?&=]*"#
let url = CrossBenchmark(
baseName: "URLWithWordBoundaries",
regex: urlRegex,
input: Inputs.url,
alsoRunSimpleWordBoundaries: true
)
url.register(&self)
}
// Benchmark from forums user @sspringer
// https://github.com/stefanspringer1/SwiftRegexBenchmarks/tree/main
mutating func addCommunityBenchmark_sspringerURL() {
let urlRegex = #"https?:\/\/([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w\.-]*)*\/?"#
let rawData = """
URLs:
http://www.google.com
https://www.google.com
http://google.com
https://google.com
http://www.google.com/
https://www.google.com/
http://google.com/
https://google.com/
http://www.google.com/index.html
https://www.google.com/index.html
http://google.com/index.html
https://google.com/index.html
"""
let data = String(repeating: rawData, count: 100)
let url = CrossBenchmark(
baseName: "Community_sspringerURL",
regex: urlRegex,
input: data
)
url.register(&self)
}
}