Basic benchmark of solutions
This commit is contained in:
parent
a2cb6ff664
commit
93c256d989
19
main.go
19
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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user