Last active
August 22, 2019 18:56
-
-
Save mikehouse/3ee92d31f7a5677b11cd134062b4e460 to your computer and use it in GitHub Desktop.
Swift time profiler
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 | |
@discardableResult | |
func measureTime<R>(name: String = #function, body: () -> R) -> R { | |
#if DEBUG | |
let startTime = CACurrentMediaTime() | |
let result: R = body() | |
let endTime = CACurrentMediaTime() | |
print("execution time of \(name): \(endTime - startTime)") | |
return result | |
#else | |
return body() | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment