Created
April 22, 2019 23:45
-
-
Save nbasham/d5bb9671e8e74abb1f8387575d8c8e46 to your computer and use it in GitHub Desktop.
A simple way to time code using Swift.
This file contains 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 | |
class CodeTimer { | |
var startTime: CFAbsoluteTime = 0 | |
init() { start() } | |
func start() { startTime = CFAbsoluteTimeGetCurrent() } | |
func log(_ message: String) { | |
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime | |
let s = String(format: "%.3f", timeElapsed) | |
print("\(message) \(s) second(s).") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage: