Skip to content

This package provides a few help functions attached to the Timer class for timing code blocks (closures).

License

Notifications You must be signed in to change notification settings

TheAngryDarling/SwiftCodeTimer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code Timer

macOS Linux Apache 2 Swift

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:

  1. Time blocks for output to user to give updates on long and complex tasks. (Helpful when debugging slow code)
  2. 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.

Usage

 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 */ })

Author

License

This project is licensed under Apache License v2.0 - see the LICENSE.md file for details

About

This package provides a few help functions attached to the Timer class for timing code blocks (closures).

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages