mirror of
https://github.com/RussellChamp/advent-of-code-2021.git
synced 2026-10-28 06:02:31 +00:00
29 lines
495 B
Go
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
|
|
}
|
|
}
|