Last active
March 2, 2023 12:32
-
-
Save mikeger/82dc3f67fe9828e1b7642601cae9c367 to your computer and use it in GitHub Desktop.
Parse Xcode tests runtime, show top 25 tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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