diff --git a/main.go b/main.go index ebb6772..b6eebd1 100644 --- a/main.go +++ b/main.go @@ -3,12 +3,23 @@ package main import ( "advent-20/solutions" "fmt" + "time" ) func main() { - fmt.Println("Day 01 part 1:\t", solutions.Day01Part01(false)) - fmt.Println("Day 01 part 2:\t", solutions.Day01Part02(false)) + runAndBenchmark("01", "1", false, solutions.Day01Part01) + runAndBenchmark("01", "2", false, solutions.Day01Part02) - fmt.Println("Day 02 part 1:\t", solutions.Day02Part01(false)) - fmt.Println("Day 02 part 2:\t", solutions.Day02Part02(false)) + runAndBenchmark("02", "1", false, solutions.Day01Part01) + runAndBenchmark("02", "2", false, solutions.Day01Part02) +} + +type execute func(bool) int + +func runAndBenchmark(day, part string, isTest bool, fn execute) { + startMs := time.Now().UnixMicro() + computation := fn(isTest) + endMs := time.Now().UnixMicro() + duration := endMs - startMs + fmt.Printf("Day %s part %s:\t%10d\t%5d micros.\n", day, part, computation, duration) }