Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serhii-londar/85e71b3915c033154adf08dd7a6eca9d to your computer and use it in GitHub Desktop.
Save serhii-londar/85e71b3915c033154adf08dd7a6eca9d to your computer and use it in GitHub Desktop.
Swift Tip: Quick Performance Timing
@discardableResult
func measure<A>(name: String = "", _ block: () -> A) -> A {
let startTime = CACurrentMediaTime()
let result = block()
let timeElapsed = CACurrentMediaTime() - startTime
print("Time: \(name) - \(timeElapsed)")
return result
}
let result = measure { (0..<1_000_000).reduce(0, +) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment