Files
zeekayandHanzo Dev c8bfbebc15 Keep ZAMA's copyright notices
This app is ZAMA's BSD 3-Clause Clear demo. The license requires its notices to
survive redistribution, and a rebrand had replaced every one of them with ours:
the LICENSE text, 66 source headers and the app's copyright string. They are
back, each with our line beside it for our changes.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-23 01:55:03 -07:00

40 lines
1.4 KiB
Swift

// Copyright © 2025 Zama. All rights reserved.
// Copyright © 2025 Lux Industries Inc.
import Foundation
func measure<T>(_ name: String, _ block: () -> T) -> T {
print("\(name) in progress…")
let start = Date()
let result = block()
let duration = Date().timeIntervalSince(start)
print(" ↳ \(name) done (\(duration.formatted(.number.precision(.fractionLength(3)))) seconds).")
return result
}
func measure<T>(_ name: String, _ block: () throws -> T) throws -> T {
print("\(name) in progress…")
let start = Date()
do {
let result = try block()
let duration = Date().timeIntervalSince(start)
print(" ↳ \(name) done (\(duration.formatted(.number.precision(.fractionLength(3)))) seconds).")
return result
} catch {
let duration = Date().timeIntervalSince(start)
print(" ↳ \(name) exception (\(duration.formatted(.number.precision(.fractionLength(3)))) seconds)")
throw error
}
}
func measureAsync<T>(_ name: String, _ operation: @escaping () async throws -> T) async rethrows -> T {
print("\(name) in progress…")
let clock = ContinuousClock()
let start = clock.now
let result = try await operation()
let duration = start.duration(to: clock.now).components.seconds
print(" ↳ \(name) done (\(duration.formatted(.number.precision(.fractionLength(3)))) seconds).")
return result
}