How to log a method’s execution time in Xcode ?

We often required to calculate how much time xcode required for execute certain chunk of code. Fortunately there is a workaround which might be used is `CFAbsoluteTimeGetCurrent()`Here i have used Big O(n^2) Time complexity you can change values & test it over xcode.

let startTime = CFAbsoluteTimeGetCurrent()
// run your work
func tempFunction(_ s: String) -> String {
    for _ in 0..<999 {
        for _ in 0..<9999 {}
    return "Got it"
let diffrence = CFAbsoluteTimeGetCurrent() - startTime
print("It required \(diffrence) seconds") // 4.7849119901657104

Leave a Comment

Your email address will not be published. Required fields are marked *