Skip to content

Instantly share code, notes, and snippets.

@mikehouse
Last active August 22, 2019 18:56
Show Gist options
  • Save mikehouse/3ee92d31f7a5677b11cd134062b4e460 to your computer and use it in GitHub Desktop.
Save mikehouse/3ee92d31f7a5677b11cd134062b4e460 to your computer and use it in GitHub Desktop.
Swift time profiler
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