Last active
January 18, 2020 15:24
-
-
Save ycui1/41ce9a2747814c21e313dbc2b2065dc1 to your computer and use it in GitHub Desktop.
This file contains 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
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