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

@ -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))

@ -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{}