Created
July 25, 2018 07:18
-
-
Save marty-suzuki/61250a8aed71d407586525788b4633eb to your computer and use it in GitHub Desktop.
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
| import Foundation | |
| let buildLog = """ | |
| """ | |
| let regex = try! NSRegularExpression(pattern: "(\\d*.\\d*)ms.*/(.*\\.swift)*", options: []) | |
| let range = NSRange(location: 0, length: (buildLog as NSString).length) | |
| let results = regex.matches(in: buildLog, options: [], range: range) | |
| let values = results.reduce([String: Double]()) { values, result in | |
| guard result.numberOfRanges > 2 else { | |
| return values | |
| } | |
| let (fileName, compileTime) = (1..<result.numberOfRanges) | |
| .reduce(("", Double(0))) { values, index in | |
| let range = result.range(at: index) | |
| if range.location == NSNotFound { | |
| return values | |
| } | |
| let substring = (buildLog as NSString).substring(with: range) | |
| if index == 1 { | |
| return (values.0, Double(substring) ?? values.1) | |
| } else { | |
| return (substring, values.1) | |
| } | |
| } | |
| if fileName.isEmpty { | |
| return values | |
| } | |
| var newValues = values | |
| if let totalCompileTime = newValues[fileName] { | |
| newValues[fileName] = totalCompileTime + compileTime | |
| } else { | |
| newValues[fileName] = compileTime | |
| } | |
| return newValues | |
| } | |
| values.forEach { | |
| print("\($0.key): \($0.value)ms") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment