aoc2021/Sources/Runner/Runner.swift

39 lines
931 B
Swift
Raw Permalink Normal View History

2021-12-05 10:43:02 +00:00
//
// File.swift
//
//
// Created by Max Nuding on 05.12.21.
//
import Foundation
public protocol Runnable {
init(inputPath: String)
func run()
}
public struct Runner {
let target: Runnable.Type
let inputPath: String
let day: String
public init(target: Runnable.Type, day: String, isTest: Bool = false) {
let inputPath = isTest ? "\(day)_test" : day
let input = Bundle.module.path(forResource: inputPath, ofType: ".txt")!
self.inputPath = input
self.target = target
self.day = day
}
public func run() {
print("Starting day \(day)")
let start = CFAbsoluteTimeGetCurrent()
let runnable = target.init(inputPath: inputPath)
runnable.run()
let end = CFAbsoluteTimeGetCurrent()
let execTimeMs = round((end - start) * 1000.0 * 100.0) / 100.0
print("Finished in \(execTimeMs)ms")
}
}