Last active
June 29, 2018 07:26
-
-
Save mlabraca/b1d958afff41a850783796cd29c7c2ed to your computer and use it in GitHub Desktop.
For a given block of code, calculates the execution time.
This file contains hidden or 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
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