Print duration
This commit is contained in:
parent
50dd18ea43
commit
e34db0fa02
1 changed files with 9 additions and 0 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
import Foundation
|
||||||
|
|
||||||
protocol Puzzle {
|
protocol Puzzle {
|
||||||
mutating func run()
|
mutating func run()
|
||||||
init()
|
init()
|
||||||
|
@ -5,8 +7,15 @@ protocol Puzzle {
|
||||||
|
|
||||||
extension Puzzle {
|
extension Puzzle {
|
||||||
static func main() {
|
static func main() {
|
||||||
|
let start = Date()
|
||||||
var instance = Self()
|
var instance = Self()
|
||||||
instance.run()
|
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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue