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:
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 */ })
This project is licensed under Apache License v2.0 - see the LICENSE.md file for details
link |
Stars: 1 |
Last commit: 4 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics