Created
August 17, 2018 02:43
-
-
Save serhii-londar/85e71b3915c033154adf08dd7a6eca9d to your computer and use it in GitHub Desktop.
Swift Tip: Quick Performance Timing
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
@discardableResult | |
func measure<A>(name: String = "", _ block: () -> A) -> A { | |
let startTime = CACurrentMediaTime() | |
let result = block() | |
let timeElapsed = CACurrentMediaTime() - startTime | |
print("Time: \(name) - \(timeElapsed)") | |
return result | |
} | |
let result = measure { (0..<1_000_000).reduce(0, +) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment