Skip to content

Instantly share code, notes, and snippets.

@crisbit
Created December 14, 2016 13:10
Show Gist options
  • Save crisbit/c43578e0781a97644e8d3e549232bce8 to your computer and use it in GitHub Desktop.
Save crisbit/c43578e0781a97644e8d3e549232bce8 to your computer and use it in GitHub Desktop.
Calculate elapsed time in Swift
let start = Date()
print("Elapsed time: \(start.timeIntervalSinceNow) seconds")
@yoni-g
Copy link

yoni-g commented Feb 25, 2021

For UI measurements it's the best solution. Thank you so much!

@PetrusM
Copy link

PetrusM commented Oct 31, 2022

I think adding a minus (or absolute value) would be better, because we would have a positive elapsed time value : print("Elapsed time: \(-start.timeIntervalSinceNow) seconds")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment