From b32dffb05e98ebf7c48f2db1bd49543c51cd68ea Mon Sep 17 00:00:00 2001 From: Michael Ilseman Date: Sat, 2 Nov 2024 10:42:57 -0600 Subject: [PATCH] Add benchmark from sspringer --- .../BenchmarkRegistration.swift | 4 +++ Sources/RegexBenchmark/Suite/URLRegex.swift | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/Sources/RegexBenchmark/BenchmarkRegistration.swift b/Sources/RegexBenchmark/BenchmarkRegistration.swift index e12502e9..c4718fb9 100644 --- a/Sources/RegexBenchmark/BenchmarkRegistration.swift +++ b/Sources/RegexBenchmark/BenchmarkRegistration.swift @@ -20,6 +20,10 @@ extension BenchmarkRunner { self.addIpAddress() self.addURLWithWordBoundaries() + + // Register community benchmarks + self.addCommunityBenchmark_sspringerURL() + // -- end of registrations -- } } diff --git a/Sources/RegexBenchmark/Suite/URLRegex.swift b/Sources/RegexBenchmark/Suite/URLRegex.swift index e5f00f4e..8140da72 100644 --- a/Sources/RegexBenchmark/Suite/URLRegex.swift +++ b/Sources/RegexBenchmark/Suite/URLRegex.swift @@ -11,4 +11,32 @@ extension BenchmarkRunner { ) 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) + } }