Print duration

This commit is contained in:
Sven Weidauer 2021-12-15 19:35:16 +01:00
parent 50dd18ea43
commit e34db0fa02

View file

@ -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))
}
}
}