File tree Expand file tree Collapse file tree 3 files changed +51
-11
lines changed Expand file tree Collapse file tree 3 files changed +51
-11
lines changed Original file line number Diff line number Diff line change @@ -54,11 +54,18 @@ public struct BenchmarkRunner {
54
54
// Register instances of Benchmark and run them
55
55
let suiteName : String
56
56
var suite : [ any RegexBenchmark ]
57
- let samples : Int = 20
57
+ let samples : Int
58
58
59
- public init ( suiteName: String ) {
59
+ public init ( _ suiteName: String ) {
60
60
self . suiteName = suiteName
61
61
self . suite = [ ]
62
+ self . samples = 20
63
+ }
64
+
65
+ public init ( _ suiteName: String , _ n: Int ) {
66
+ self . suiteName = suiteName
67
+ self . suite = [ ]
68
+ self . samples = n
62
69
}
63
70
64
71
public mutating func register( _ new: some RegexBenchmark ) {
@@ -101,6 +108,15 @@ public struct BenchmarkRunner {
101
108
print ( " - \( b. name) \( measure ( benchmark: b) ) " )
102
109
}
103
110
}
111
+
112
+ public func profile( ) {
113
+ print ( " Starting " )
114
+ for b in suite {
115
+ print ( " - \( b. name) " )
116
+ b. run ( )
117
+ print ( " - done " )
118
+ }
119
+ }
104
120
}
105
121
106
122
// nom nom nom, consume the argument
Original file line number Diff line number Diff line change
1
+ import ArgumentParser
2
+
3
+ @main
4
+ struct Runner : ParsableCommand {
5
+ @Argument ( help: " Names of benchmarks to run " )
6
+ var specificBenchmarks : [ String ] = [ ]
7
+
8
+ @Option ( help: " Run only once for profiling purposes " )
9
+ var profile = false
10
+
11
+ @Option ( help: " How many samples to collect for each benchmark " )
12
+ var samples = 20
13
+
14
+ func makeRunner( ) -> BenchmarkRunner {
15
+ var benchmark = BenchmarkRunner ( " RegexBench " , samples)
16
+ benchmark. addReluctantQuant ( )
17
+ benchmark. addBacktracking ( )
18
+ benchmark. addCSS ( )
19
+ benchmark. addFirstMatch ( )
20
+ return benchmark
21
+ }
22
+ mutating func run( ) throws {
23
+ var runner = makeRunner ( )
24
+ if !self . specificBenchmarks. isEmpty {
25
+ runner. suite = runner. suite. filter { b in specificBenchmarks. contains ( b. name) }
26
+ }
27
+ if profile {
28
+ runner. profile ( )
29
+ } else {
30
+ runner. run ( )
31
+ }
32
+ }
33
+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments