start := time.Now()
// Code to measure
duration := time.Since(start)
// Formatted string, such as "2h3m0.5s" or "4.503μs"
fmt.Println(duration)
// Nanoseconds as int64
fmt.Println(duration.Nanoseconds())
测量函数调用
func foo() {
defer duration(track("foo"))
// Code to measure
}
测量一段代码
测量函数调用