CPUTimeStamp
public struct CPUTimeStamp
extension CPUTimeStamp: Hashable
extension CPUTimeStamp: Equatable
extension CPUTimeStamp: Comparable
CPUTimeStamp: High-precision, monotonic CPU time for measurements and TTL logic.
- Monotonic source based on
mach_absolute_time
converted via cachedmach_timebase_info
- Nanosecond-level precision with safe conversion order to avoid overflow
Arithmetic and comparison operators for intervals and ordering
Notes:
- Intended for measuring intervals and scheduling expirations; not wall-clock time
- Thread-safe and value-semantic; creation is fast
infinity
andzero
helpers simplify sentinel usage
-
A timestamp representing positive infinity (never expires).
Declaration
Swift
public static let infinity: `Self`
-
Creates a timestamp representing the current moment.
Declaration
Swift
public static func now() -> CPUTimeStamp
-
A timestamp representing zero time (epoch).
Declaration
Swift
public static var zero: `Self`
-
Initialize with current CPU time.
Declaration
Swift
public init()
-
Returns the time interval since CPU start in seconds.
Declaration
Swift
public func timeIntervalSinceCPUStart() -> TimeInterval
-
Implements comparison between timestamps.
Declaration
Swift
public static func < (lhs: `Self`, rhs: `Self`) -> Bool
-
Adds a time interval to a timestamp.
Declaration
Swift
static func + (lhs: `Self`, rhs: TimeInterval) -> CPUTimeStamp
Return Value
A new timestamp offset by the specified interval.
-
Subtracts a time interval from a timestamp.
Declaration
Swift
static func - (lhs: `Self`, rhs: TimeInterval) -> CPUTimeStamp
Return Value
A new timestamp offset backwards by the specified interval.
-
Calculates the time interval between two timestamps.
Declaration
Swift
func timeIntervalSince(_ other: `Self`) -> TimeInterval
Parameters
other
The reference timestamp to measure against.
Return Value
Time interval in seconds between the timestamps.
-
Subtracts two timestamps to get the interval between them.
Declaration
Swift
static func - (lhs: `Self`, rhs: `Self`) -> TimeInterval
Return Value
Time interval in seconds.