Skip to content

Instantly share code, notes, and snippets.

@Catfish-Man
Created April 6, 2019 07:31
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 Catfish-Man/f31a387f166a1121f57390cce573c166 to your computer and use it in GitHub Desktop.
Save Catfish-Man/f31a387f166a1121f57390cce573c166 to your computer and use it in GitHub Desktop.
Shell and Swift versions of a little script to compare Swift benchmark output files
/*
Shell version:
paste -d , oldoutput.txt output.txt | awk -F "," '{printf "%s %s %s %f\n", $2, $8, $16, $8 / $16}' | sort -k4 | egrep -v "(1\.0|0\.9[1-9])"
*/
import Foundation
// "paste -d , oldfile.txt newfile.txt"
let paths = CommandLine.arguments[1...2].map(URL.init(fileURLWithPath:))
let files = paths.map {
try! String(contentsOf: $0.standardized, encoding: .utf8)
}
let lines = files.map { $0.split(separator: "\n") }
let merged = zip(lines[0], lines[1]).map { "\($0),\($1)" }
// awk -F "," '{printf "%s %s %s %f\n", $2, $8, $16, $8 / $16}'
// Almost, anyway… leaving the last field as a Double for now
let results = merged.map { (line) -> (text: String, ratio: Double) in
let columns = line.split(separator: ",")
return (
"\(columns[1]) \(columns[7]) \(columns[15])",
Double(columns[7])! / Double(columns[15])!
)
}
//sort -k4
let sorted = results.sorted { $0.ratio < $1.ratio }
// Last bit of the 'awk' invocation since we're done with using them numerically
let formatted = sorted.map { "\($0.text) \($0.ratio)" }
//egrep -v "(1\.0|0\.9[1-9])"
let filtered = formatted.filter {
$0.range(of: #"(1\.0|0\.9[1-9])"#, options: .regularExpression) == nil
}
print(filtered)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment