Skip to content

Instantly share code, notes, and snippets.

@mlabraca
Last active June 29, 2018 07:26
Show Gist options
  • Save mlabraca/b1d958afff41a850783796cd29c7c2ed to your computer and use it in GitHub Desktop.
Save mlabraca/b1d958afff41a850783796cd29c7c2ed to your computer and use it in GitHub Desktop.
For a given block of code, calculates the execution time.
func executionTimeInterval(block: () -> ()) -> CFTimeInterval {
let start = Date() // <<<<<<<<<< Start time
block()
let end = Date() // <<<<<<<<<< end time
let timeInterval: Double = end.timeIntervalSince(start);
print(timeInterval)
return timeInterval
}
//Example of use
executionTimeInterval { for _ in 0..<10 { } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment