Skip to content

Instantly share code, notes, and snippets.

@yo1995
Created December 12, 2024 17:34
Show Gist options
  • Save yo1995/f7f60cf00e04143bb15424371d6c7ae0 to your computer and use it in GitHub Desktop.
Save yo1995/f7f60cf00e04143bb15424371d6c7ae0 to your computer and use it in GitHub Desktop.
Measure elapsed time for Swift function
private func measureElapsedTime(_ operation: () throws -> Void) throws -> Double {
let startTime = DispatchTime.now()
try operation()
let endTime = DispatchTime.now()
let elapsedTime = endTime.uptimeNanoseconds - startTime.uptimeNanoseconds
let elapsedTimeInMilliSeconds = Double(elapsedTime) / 1_000_000.0
return elapsedTimeInMilliSeconds
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment