Swiftpack.co - TheAngryDarling/SwiftCodeTimer as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by TheAngryDarling.
TheAngryDarling/SwiftCodeTimer 1.0.1
This package provides a few help functions attached to the Timer class for timing code blocks (closures).
⭐️ 1
🕓 4 years ago
.package(url: "https://github.com/TheAngryDarling/SwiftCodeTimer.git", from: "1.0.1")

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

GitHub

link
Stars: 1
Last commit: 4 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics