From a67ecb3a831c660097a4fb3d0ba10a9479b9425e Mon Sep 17 00:00:00 2001 From: Karl Spickermann Date: Wed, 7 Dec 2022 16:45:39 +0100 Subject: [PATCH] Measure Run Time --- day6/day6.go | 6 +++--- helper/helper.go | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/day6/day6.go b/day6/day6.go index a57aec2..499c62c 100644 --- a/day6/day6.go +++ b/day6/day6.go @@ -3,12 +3,12 @@ package main import ( "AOC2022/helper" "fmt" - "os" ) func main() { - args := os.Args[1:] - lines := helper.ReadTextFile(args[0]) + //args := os.Args[1:] + lines := helper.ReadTextFile("day6/input") + defer helper.MeasureTime("Task One")() for _, line := range lines { fmt.Println(getIndexOfFirstNUniqueCharacters(4, line)) fmt.Println(getIndexOfFirstNUniqueCharacters(14, line)) diff --git a/helper/helper.go b/helper/helper.go index 27ff804..846efbb 100644 --- a/helper/helper.go +++ b/helper/helper.go @@ -1,8 +1,10 @@ package helper import ( + "fmt" "os" "strings" + "time" ) func check(e error) { @@ -33,6 +35,14 @@ func GetKeysOfSetMap[T int | string](inputMap map[T]bool) []T { return keys } +func MeasureTime(process string) func() { + fmt.Printf("Start %s\n", process) + start := time.Now() + return func() { + fmt.Printf("Time taken by %s is %v\n", process, time.Since(start)) + } +} + func FindRepeatedItems[T int | int64](itemgroup1, itemgroup2 []T) []T { elementsCompartment1 := map[T]bool{} repeatedElemnts := map[T]bool{}