A simple and lightweight stopwatch library for Swift.
- High-precision timing using
mach_absolute_time()
- Non-copyable struct design
- Simple and intuitive API
- Microsecond and millisecond precision
Add the following to your Package.swift
:
dependencies: [
.package(url: "https://github.com/FluidGroup/swift-stopwatch.git", from: "1.0.0")
]
import Stopwatch
// Create a stopwatch with a name
let stopwatch = Stopwatch(name: "My Operation")
// Do some work...
// End the stopwatch and print the elapsed time
stopwatch.end()
The output will show the elapsed time in both microseconds (μs) and milliseconds (ms).
- Swift 6.0 or later