Created
September 3, 2019 17:17
-
-
Save hishma/db12b03b9a31945150a3ea946baea3f6 to your computer and use it in GitHub Desktop.
Prints the time taken to execute a closure.
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
/// Prints the time taken to execute a closure. | |
/// | |
/// Note: Only for debugging purposes. | |
public func measure<T>(_ label: String = "", _ f: () throws -> (T)) rethrows -> T { | |
let startTime = Date() | |
let result = try f() | |
let endTime = Date().timeIntervalSince(startTime) | |
print("\(label): Time taken", endTime) | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment