Measuring function execution time

This is a very quick one. For an app I’m working on I wanted to measure how long it took a given function to complete. 

I typically don’t do this, as most functions are very fast, but this one involved a server fetch and some background processing. Anyhow, I’m getting distracted, here it is -easy as pie-:


let startTime = Date()




let endTime = Date()

let timeElapsed: Double = endTime.timeIntervalSince(startTime)


print(“Time taken \(timeElapsed) seconds”)


Questions / comments / suggestions? I’m at @MarcMasVi