Files
advent-of-code-2021/utils/timer/timer.go
T
2021-12-15 16:52:42 -05:00

29 lines
495 B
Go

package timer
import (
"AoC2021/utils/color"
"AoC2021/utils/log"
"fmt"
"time"
)
var lastTime time.Time
func Start() {
lastTime = time.Now()
}
func Tick() {
now := time.Now()
fmt.Printf(color.Yellow+"[Time taken: %s]\n"+color.Reset, now.Sub(lastTime).String())
lastTime = now
}
func TickAtLevel(logLevel int) {
if log.LOG_LEVEL >= logLevel {
now := time.Now()
log.Printf(logLevel, color.Yellow+"[Time taken: %s]\n"+color.Reset, now.Sub(lastTime).String())
lastTime = now
}
}