Skip to content

Instantly share code, notes, and snippets.

@jairobjunior
Created July 6, 2016 17:27
Show Gist options
  • Save jairobjunior/d694080c2a59981838a1b6b0511df46a to your computer and use it in GitHub Desktop.
Save jairobjunior/d694080c2a59981838a1b6b0511df46a to your computer and use it in GitHub Desktop.
Simple benchmarking func in Swift to display block execution time.
public func benchmarking(operationName: String, operation: ()->()) {
let startTime = CFAbsoluteTimeGetCurrent()
operation()
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
print("Time elapsed for \(operationName): \(timeElapsed) s")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment