Skip to content

Instantly share code, notes, and snippets.

@ycui1
Last active January 18, 2020 15:24
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 ycui1/41ce9a2747814c21e313dbc2b2065dc1 to your computer and use it in GitHub Desktop.
Save ycui1/41ce9a2747814c21e313dbc2b2065dc1 to your computer and use it in GitHub Desktop.
var comparisonRecords = [(String, Int, Double, Double)]()
let trials = 10
func compareOperations(name: String, repeats: Int, arrayOperation: ()->(), setOperation: ()->()) {
for trial in 1...trials {
let arrayStartTime = CFAbsoluteTimeGetCurrent()
for _ in 1...repeats {
arrayOperation()
}
let arrayTimeInterval = (CFAbsoluteTimeGetCurrent() - arrayStartTime)*1000
let setStartTime = CFAbsoluteTimeGetCurrent()
for _ in 1...repeats {
setOperation()
}
let setTimeInterval = (CFAbsoluteTimeGetCurrent() - setStartTime)*1000
comparisonRecords.append((name, trial, arrayTimeInterval, setTimeInterval))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment