File: CLI.swift

package info (click to toggle)
swiftlang 6.1.3-4
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 2,791,644 kB
  • sloc: cpp: 9,901,738; ansic: 2,201,433; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (131 lines) | stat: -rw-r--r-- 3,704 bytes parent folder | download
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
import ArgumentParser

@main
struct Runner: ParsableCommand {
  @Argument(help: "Patterns for benchmarks to run")
  var specificBenchmarks: [String] = []

  @Option(help: "How many samples to collect for each benchmark")
  var samples = 30

  @Flag(help: "Debug benchmark regexes")
  var debug = false
  
  @Option(help: "Load results from this file instead of rerunning")
  var load: String?

  @Option(help: "The file results should be saved to")
  var save: String?

  @Option(help: "The result file to compare against")
  var compare: String?

  @Option(help: "Compare compile times with the given results file")
  var compareCompileTime: String?
  
  @Flag(help: "Show comparison chart")
  var showChart: Bool = false
  
  @Flag(help: "Compare with NSRegularExpression")
  var compareWithNS: Bool = false
  
  @Option(help: "Save comparison results as csv")
  var saveComparison: String?

  @Option(help: "Save benchmark results as csv")
  var saveCSV: String?

  @Flag(help: "Quiet mode")
  var quiet = false

  @Flag(help: "Exclude running NSRegex benchmarks")
  var excludeNs = false

  @Flag(help: "Rather than specify specific-benchmarks as patterns, use exact names")
  var exactName = false

  @Flag(help: """
Enable tracing of the engine (warning: lots of output). Prints out processor state each cycle

Note: swift-experimental-string-processing must be built with processor measurements enabled
swift build -c release -Xswiftc -DPROCESSOR_MEASUREMENTS_ENABLED

""")
  var enableTracing: Bool = false

  @Flag(help: """
Enable engine metrics (warning: lots of output). Prints out cycle count, instruction counts, number of backtracks

Note: swift-experimental-string-processing must be built with processor measurements enabled
swift build -c release -Xswiftc -DPROCESSOR_MEASUREMENTS_ENABLED

""")
  var enableMetrics: Bool = false
  
  @Flag(help: "Include firstMatch benchmarks in CrossBenchmark (off by default)")
  var includeFirst: Bool = false

  mutating func run() throws {
    var runner = BenchmarkRunner(
      suiteName: "DefaultRegexSuite",
      samples: samples,
      quiet: quiet,
      enableTracing: enableTracing,
      enableMetrics: enableMetrics,
      includeFirstOverride: includeFirst)
    
    runner.registerDefault()
    
    if !self.specificBenchmarks.isEmpty {
      runner.suite = runner.suite.filter { b in
        specificBenchmarks.contains { pattern in
          if exactName {
            return pattern == b.name
          }

          return try! Regex(pattern).firstMatch(in: b.name) != nil
        }
      }
    }
    if debug {
      runner.debug()
      return
    }
    
    if let loadFile = load {
      try runner.load(from: loadFile)
      if excludeNs {
        runner.results.results = runner.results.results.filter {
          !$0.key.contains("_NS")
        }
      }
    } else {
      if excludeNs {
        runner.suite = runner.suite.filter { b in !b.name.contains("_NS") }
      }
      runner.run()
    }
    if let saveFile = save {
      try runner.save(to: saveFile)
    }
    if saveComparison != nil && compareWithNS && compare != nil {
      print("Unable to save both comparison results, specify only one compare operation")
      return
    }
    if compareWithNS {
      try runner.compareWithNS(showChart: showChart, saveTo: saveComparison)
    }
    if let compareFile = compare {
      try runner.compare(
        against: compareFile,
        showChart: showChart,
        saveTo: saveComparison)
    }
    if let compareFile = compareCompileTime {
      try runner.compareCompileTimes(against: compareFile, showChart: showChart)
    }
    if let csvPath = saveCSV {
      try runner.saveCSV(to: csvPath)
    }
  }
}