Skip to content

Instantly share code, notes, and snippets.

@wtsnz
Created September 14, 2015 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wtsnz/41d7314f0c17d2206139 to your computer and use it in GitHub Desktop.
Save wtsnz/41d7314f0c17d2206139 to your computer and use it in GitHub Desktop.
A simple way to time functions in swift
import Foundation
import CoreFoundation
class Timer {
let startTime:CFAbsoluteTime
var endTime:CFAbsoluteTime?
init() {
startTime = CFAbsoluteTimeGetCurrent()
}
func stop() -> CFAbsoluteTime {
endTime = CFAbsoluteTimeGetCurrent()
return duration!
}
var duration:CFAbsoluteTime? {
if let endTime = endTime {
return endTime - startTime
} else {
return nil
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment