1519.

Measure execution time in Go (Golang)

gosamples.dev/measure-time

A good snippet. I used it at work.

func track(name string) func() {
    start := time.Now()
    return func() {
        log.Printf("%s, execution time %s\n", name, time.Since(start))
    }
}

func main() {
    defer track("main")() // do not forget about the second parentheses
    time.Sleep(2 * time.Second)
}