I'm having a problem where time.Since() is producing 0s. Can anyone explain out of the blue why this may happen? I'm trying to measure the execution time of a webserver call.
func handle(f http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
log.Println(r.URL.Path)
start := time.Now()
f(w, r)
elapsed := time.Since(start)
log.Printf("took %s", elapsed)
}
}
It produces this output, where it sometimes gives "took 0s". Am I missing something here?
2019/01/24 23:28:45 /hello
2019/01/24 23:28:45 took 1.9878ms
2019/01/24 23:28:45 /hello
2019/01/24 23:28:45 took 998.6µs
2019/01/24 23:28:46 /hello
2019/01/24 23:28:46 took 1.0007ms
2019/01/24 23:28:46 /hello
2019/01/24 23:28:46 took 0s
2019/01/24 23:28:46 /hello
2019/01/24 23:28:46 took 0s
2019/01/24 23:28:46 /hello
2019/01/24 23:28:46 took 998.8µs
2019/01/24 23:28:47 /hello
2019/01/24 23:28:47 took 0s
2019/01/24 23:28:47 /hello
2019/01/24 23:28:47 took 0s