Skip to content

Instantly share code, notes, and snippets.

@amfathi
Last active April 15, 2021 14:22
Show Gist options
  • Save amfathi/5a3a16ab9a1ab0eebe68162eb1002d05 to your computer and use it in GitHub Desktop.
Save amfathi/5a3a16ab9a1ab0eebe68162eb1002d05 to your computer and use it in GitHub Desktop.
A utility function to calculate and print the running time for a code block in milliseconds.
func runningTime(clousure: () -> Void) {
let start = DispatchTime.now()
clousure()
let end = DispatchTime.now()
let runTime = CLongDouble(end.uptimeNanoseconds - start.uptimeNanoseconds) / 1e6
print("runTime: \(runTime) ms")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment