Skip to content

Instantly share code, notes, and snippets.

@MugunthKumar
Last active February 22, 2016 23:34
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MugunthKumar/d8199de02510e2294f17 to your computer and use it in GitHub Desktop.
Save MugunthKumar/d8199de02510e2294f17 to your computer and use it in GitHub Desktop.
Measures Time Taken for a closure to run
func measure(prefix: String = "Time Taken", closure:()->()) {
let a = CFAbsoluteTimeGetCurrent()
closure()
let b = CFAbsoluteTimeGetCurrent()
let m = ((b-a) * 1000.0)
print("\(prefix): \(m) ms")
}
@JadenGeller
Copy link

Why is String optional?

@arvindhsukumar
Copy link

Isn't it preferable to have the optional arguments in the func signature at the end?

@MugunthKumar
Copy link
Author

Thanks @JadenGaller
Updated the gist

@MugunthKumar
Copy link
Author

@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