This package provides a few help functions attached to the Timer class for timing code blocks (closures). Timing of code bocks can be helpful in a couple of ways. The purposes I had in mind while writing this were:
- Time blocks for output to user to give updates on long and complex tasks. (Helpful when debugging slow code)
- Time blocks of code that use 3rd party libraries and/or web services to monitor if theres been changes in performance that is causing my applications to slow down.
let duration: TimeInterval = Timer.time { /* Code Block Here */ }
let duration: TimeInterval = Timer.time( { /* Code Block Here */ } )
let duration: TimeInterval = Timer.time( block: /* AutoClosure Code Block Here */ )
let r: (TimeInterval, Results) = Timer.timeWithResults { /* Code Block Here, returning Results */ }
let r: (TimeInterval, Results) = Timer.timeWithResults( { /* Code Block Here, returning Results */ } )
let r: (TimeInterval, Results) = Timer.timeWithResults( block: /* AutoClosure Code Block Here, returning Results */ )
func callback(_ timer: Timer, _ duration: TimeInterval) {
// Retrieve duration here
}
let timer = Timer.scheduledTimedTimer(withTimeInterval: time, repeats: false, callback: callback) { /* Code Block Here */ }
let timer = Timer.scheduledTimedTimer(withTimeInterval: time, repeats: false, callback: callback, { /* Code Block Here */ })
let timer = Timer.scheduledTimedTimer(withTimeInterval: time, repeats: false, callback: callback, block: { /* AutoClosure Code Block Here */ })
// Results = returning type from block code
func callbackWithResults(_ timer: Timer, _ duration: TimeInterval, _ results: Results) {
// Retrieve duration here
// Retrieve results
}
let timer = Timer.scheduledTimedTimerWithResults(withTimeInterval: time, repeats: false, callback: callbackWithResults) { /* Code Block Here, returning Results */ }
let timer = Timer.scheduledTimedTimerWithResults(withTimeInterval: time, repeats: false, callback: callbackWithResults, { /* Code Block Here, returning Results */ })
let timer = Timer.scheduledTimedTimerWithResults(withTimeInterval: time, repeats: false, callback: callbackWithResults, block: { /* AutoClosure Code Block Here, returning Results */ })
- Tyler Anger - Initial work - TheAngryDarling
This project is licensed under Apache License v2.0 - see the LICENSE.md file for details