Files
divkit/client/ios/DivKit/Debug/TimeMeasure.swift
T
pkurchatov dd8ac62802 Xcode 16.2 / iOS 18.2 compatibility
commit_hash:412e18597618717211e71006d0adb10e4cb88999
2025-01-17 17:38:03 +03:00

47 lines
839 B
Swift

import Foundation
import VGSL
public final class TimeMeasure: @unchecked Sendable {
public struct Time {
public var value: Int
public var status: Status
public var description: String {
"\(status.rawValue.capitalized): \(value)"
}
}
public enum Status: String {
case cold
case warm
}
private var startTime: Date?
private var status: Status = .cold
public private(set) var time: Time?
init() {}
public func updateMeasure<T>(action: () throws -> T) throws -> T {
start()
let result = try action()
stop()
return result
}
private func start() {
startTime = Date()
}
private func stop() {
if let startTime {
time = Time(
value: Int(Date().timeIntervalSince(startTime) * 1000),
status: status
)
status = .warm
}
}
}