Skip to content

Instantly share code, notes, and snippets.

@mikeger
Last active March 2, 2023 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeger/82dc3f67fe9828e1b7642601cae9c367 to your computer and use it in GitHub Desktop.
Save mikeger/82dc3f67fe9828e1b7642601cae9c367 to your computer and use it in GitHub Desktop.
Parse Xcode tests runtime, show top 25 tests
#!/usr/bin/swift
import Foundation
import RegexBuilder
var lines: [String] = []
while let line = readLine() {
lines.append(line)
}
let regex = Regex {
One("(")
Capture {
OneOrMore(.digit)
One(".")
OneOrMore(.digit)
} transform: {
return Double($0)
}
ZeroOrMore(.any)
One(" seconds")
}
struct ParsedLine {
let line: String
let duration: TimeInterval
}
let parsedLines: [ParsedLine] = lines.compactMap { line -> ParsedLine? in
guard let parsed = line.firstMatch(of: regex),
let double = parsed.1 else {
return nil
}
return ParsedLine(line: line, duration: double)
}
let top = parsedLines.sorted { l, r in
return l.duration > r.duration
}.prefix(25)
print("Total lines: \(lines.count), match: \(parsedLines.count)")
print("Top 25:")
top.forEach {
print($0.line)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment