Skip to content

Commit d81a42a

Browse files
committed
swift-xcodegen: Reimplement printingTimeTaken using ContinuousClock
`ContinuousClock` is more lightweight, and Foundation has a handy API for formatting the resulting duration.
1 parent 22abc55 commit d81a42a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

utils/swift-xcodegen/Sources/swift-xcodegen/SwiftXcodegen.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,22 @@ struct SwiftXcodegen: AsyncParsableCommand, Sendable {
402402
}
403403

404404
func printingTimeTaken<T>(_ fn: () async throws -> T) async rethrows -> T {
405-
let start = Date()
405+
let start = ContinuousClock.now
406406
let result = try await fn()
407+
let end = ContinuousClock.now
408+
409+
let duration = start.duration(to: end)
407410

408411
// Note we don't print the time taken when we fail.
409-
let delta = Date().timeIntervalSince(start)
410-
log.info("Successfully generated in \(Int((delta * 1000).rounded()))ms")
412+
var message = "Successfully generated in "
413+
message += duration.formatted(
414+
.units(
415+
allowed: [.seconds],
416+
width: .narrow,
417+
fractionalPart: .init(lengthLimits: 0...3, roundingRule: .up)
418+
)
419+
)
420+
log.info(message)
411421

412422
return result
413423
}

0 commit comments

Comments
 (0)