Skip to content

Commit 3e650cb

Browse files
committed
Remove top level code
top level code is real weird, let's not talk about it
1 parent 98992b0 commit 3e650cb

File tree

6 files changed

+1729
-1687
lines changed

6 files changed

+1729
-1687
lines changed

Sources/RegexBenchmark/Benchmark.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public struct BenchmarkRunner {
5454
// Register instances of Benchmark and run them
5555
let suiteName: String
5656
var suite: [any RegexBenchmark]
57-
let samples: Int = 20
57+
let samples: Int = 40
5858

5959
public init(suiteName: String) {
6060
self.suiteName = suiteName
@@ -88,6 +88,9 @@ public struct BenchmarkRunner {
8888
let time = end.elapsedTime(since: start)
8989
times.append(time)
9090
}
91+
// todo: compute stdev and warn if it's too large
92+
93+
// return median time
9194
times.sort()
9295
return times[samples/2]
9396
}

Sources/RegexBenchmark/Suite/Backtracking.swift

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,40 @@ import Foundation
66

77
extension BenchmarkRunner {
88
mutating func addBacktracking() {
9-
register(new: basicBacktrack)
10-
register(new: basicBacktrackNS)
11-
}
12-
}
9+
let r = "^ +A"
10+
let s = String(repeating: " ", count: 1000)
1311

12+
let basicBacktrack = Benchmark(
13+
name: "BasicBacktrack",
14+
regex: try! Regex(r),
15+
ty: .enumerate,
16+
target: s
17+
)
1418

15-
private let r = " +A"
16-
private let s = String(repeating: " ", count: 100)
19+
let basicBacktrackNS = NSBenchmark(
20+
name: "BasicBacktrackNS",
21+
regex: try! NSRegularExpression(pattern: r),
22+
ty: .all,
23+
target: s
24+
)
1725

18-
private let basicBacktrack = Benchmark(
19-
name: "BasicBacktrack",
20-
regex: try! Regex(r),
21-
ty: .enumerate,
22-
target: s
23-
)
26+
let basicBacktrackFirstMatch = Benchmark(
27+
name: "BasicBacktrackFirstMatch",
28+
regex: try! Regex(r),
29+
ty: .first,
30+
target: s
31+
)
2432

25-
private let basicBacktrackNS = NSBenchmark(
26-
name: "BasicBacktrackNS",
27-
regex: try! NSRegularExpression(pattern: r),
28-
ty: .all,
29-
target: s
30-
)
33+
let basicBacktrackNSFirstMatch = NSBenchmark(
34+
name: "BasicBacktrackNSFirstMatch",
35+
regex: try! NSRegularExpression(pattern: r),
36+
ty: .first,
37+
target: s
38+
)
39+
40+
register(new: basicBacktrack)
41+
register(new: basicBacktrackNS)
42+
register(new: basicBacktrackFirstMatch)
43+
register(new: basicBacktrackNSFirstMatch)
44+
}
45+
}

0 commit comments

Comments
 (0)