-
-
Save barbietunnie/61423bbc149a9ff00d28 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
import Foundation | |
public func profiling<R>(label: String, @noescape _ block: () -> R) -> R { | |
NSLog("*** %@...", label) | |
let start = NSDate() | |
defer { | |
let end = NSDate() | |
NSLog("*** %@ took %5.3g seconds", label, end.timeIntervalSinceDate(start)) | |
} | |
return block() | |
} | |
let result: Int? = profiling("heavy computation") { | |
NSLog("Really computing hard now") | |
return Int("123") | |
} | |
// 2015-06-09 22:32:48.811 repl_swift[39408:2024531] *** heavy computation... | |
// 2015-06-09 22:32:48.811 repl_swift[39408:2024531] Really computing hard now | |
// 2015-06-09 22:32:48.812 repl_swift[39408:2024531] *** heavy computation took 0.000195 seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment