Created
September 14, 2015 06:25
-
-
Save wtsnz/41d7314f0c17d2206139 to your computer and use it in GitHub Desktop.
A simple way to time functions in swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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