import Dispatch
import Foundation

struct MonotonicTimer: Sendable {
    private let startedAtNanoseconds: UInt64

    init() {
        startedAtNanoseconds = DispatchTime.now().uptimeNanoseconds
    }

    var elapsedSeconds: TimeInterval {
        let now = DispatchTime.now().uptimeNanoseconds
        guard now >= startedAtNanoseconds else { return 0 }
        return TimeInterval(now - startedAtNanoseconds) / 1_000_000_000
    }
}
