Last active
February 22, 2016 23:34
-
-
Save MKSG-MugunthKumar/d8199de02510e2294f17 to your computer and use it in GitHub Desktop.
Measures Time Taken for a closure to run
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
func measure(prefix: String = "Time Taken", closure:()->()) { | |
let a = CFAbsoluteTimeGetCurrent() | |
closure() | |
let b = CFAbsoluteTimeGetCurrent() | |
let m = ((b-a) * 1000.0) | |
print("\(prefix): \(m) ms") | |
} |
Isn't it preferable to have the optional arguments in the func signature at the end?
Thanks @JadenGaller
Updated the gist
@arvindhsukumar Except when the last argument is a closure.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why is String optional?