Update Timer.measure() to use DispatchTime instead of Date

This commit is contained in:
MrLotU 2019-11-10 17:20:46 +01:00 committed by Konrad `ktoso` Malawski
parent c471ec9b35
commit 49431459f9
1 changed files with 3 additions and 2 deletions

View File

@ -26,9 +26,10 @@ public extension Timer {
@inlinable
static func measure<T>(label: String, dimensions: [(String, String)] = [], body: @escaping () throws -> T) rethrows -> T {
let timer = Timer(label: label, dimensions: dimensions)
let start = Date()
let start = DispatchTime.now().uptimeNanoseconds
defer {
timer.record(Date().timeIntervalSince(start))
let delta = DispatchTime.now().uptimeNanoseconds - start
timer.recordNanoseconds(delta)
}
return try body()
}