Noticed during our work on apple/swift-cluster-membership#70 and other projects this pattern:
extension Timer {
/// Records time interval between the passed in `since` dispatch time and `now`.
func recordInterval(since: DispatchTime, now: DispatchTime = .now()) {
self.recordNanoseconds(now.uptimeNanoseconds - since.uptimeNanoseconds)
}
}
emerges a lot when a message contains "sent at" or something like that, and then reporting metrics becomes timer.recordInterval(since: message.sentAt) leaving the user without any having to dance around math with the time amounts