29 lines
865 B
Swift
29 lines
865 B
Swift
import Foundation
|
|
import os
|
|
|
|
enum PerformanceLogger {
|
|
private static let logger = Logger(
|
|
subsystem: Bundle.main.bundleIdentifier ?? "Andromida",
|
|
category: "Performance"
|
|
)
|
|
|
|
static func measure<T>(_ name: String, _ block: () -> T) -> T {
|
|
#if DEBUG
|
|
let start = CFAbsoluteTimeGetCurrent()
|
|
let result = block()
|
|
let duration = CFAbsoluteTimeGetCurrent() - start
|
|
logger.info("\(name, privacy: .public) took \(duration, format: .fixed(precision: 3))s")
|
|
return result
|
|
#else
|
|
return block()
|
|
#endif
|
|
}
|
|
|
|
static func logDuration(_ name: String, from start: CFAbsoluteTime) {
|
|
#if DEBUG
|
|
let duration = CFAbsoluteTimeGetCurrent() - start
|
|
logger.info("\(name, privacy: .public) took \(duration, format: .fixed(precision: 3))s")
|
|
#endif
|
|
}
|
|
}
|