I've written the following function that when used with Defer
will surely do the trick but is there something in standard library I could use for this? I'm looking something similar to Python timeit
which I could use directly from the shell?
package main
import (
"fmt"
"time"
)
func main() {
defer timeTrack(time.Now(), "looptest")
nums := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
var m []int
for n := range nums {
if n%2 == 0 {
m = append(m, n)
}
}
}
func timeTrack(start time.Time, name string) {
elapsed := time.Since(start)
fmt.Printf("%s took %s", name, elapsed)
}