From e34db0fa0206bc196f7f07ea7cb31c6efdbc48bc Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Wed, 15 Dec 2021 19:35:16 +0100 Subject: [PATCH] Print duration --- common.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/common.swift b/common.swift index 1df8bf4..3716c97 100644 --- a/common.swift +++ b/common.swift @@ -1,3 +1,5 @@ +import Foundation + protocol Puzzle { mutating func run() init() @@ -5,8 +7,15 @@ protocol Puzzle { extension Puzzle { static func main() { + let start = Date() var instance = Self() instance.run() + let duration = Date().timeIntervalSince(start) + if duration > 1 { + print(String(format: "Took %.2f s", duration)) + } else { + print(String(format: "Took %.2f ms", 1000 * duration)) + } } }