Measure Run Time

This commit is contained in:
Karl Spickermann 2022-12-07 16:45:39 +01:00
parent dceacf5bd6
commit a67ecb3a83
2 changed files with 13 additions and 3 deletions

View File

@ -3,12 +3,12 @@ package main
import ( import (
"AOC2022/helper" "AOC2022/helper"
"fmt" "fmt"
"os"
) )
func main() { func main() {
args := os.Args[1:] //args := os.Args[1:]
lines := helper.ReadTextFile(args[0]) lines := helper.ReadTextFile("day6/input")
defer helper.MeasureTime("Task One")()
for _, line := range lines { for _, line := range lines {
fmt.Println(getIndexOfFirstNUniqueCharacters(4, line)) fmt.Println(getIndexOfFirstNUniqueCharacters(4, line))
fmt.Println(getIndexOfFirstNUniqueCharacters(14, line)) fmt.Println(getIndexOfFirstNUniqueCharacters(14, line))

View File

@ -1,8 +1,10 @@
package helper package helper
import ( import (
"fmt"
"os" "os"
"strings" "strings"
"time"
) )
func check(e error) { func check(e error) {
@ -33,6 +35,14 @@ func GetKeysOfSetMap[T int | string](inputMap map[T]bool) []T {
return keys 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 { func FindRepeatedItems[T int | int64](itemgroup1, itemgroup2 []T) []T {
elementsCompartment1 := map[T]bool{} elementsCompartment1 := map[T]bool{}
repeatedElemnts := map[T]bool{} repeatedElemnts := map[T]bool{}