Go has an easy and efficient way of dealing with time. It is flexible, well prepared, and by far the easiest way to produce results.
To measure a runtime execution (not benchmark) for time-sensitive operations on the fly, you can do one of the following recipes depending on your reference points.
package main
import (
"fmt"
"time"
)
func main() {
start := time.Now()
fmt.Println("Hello World")
duration := time.Since(start)
fmt.Printf("Time taken: %v\n", duration)
}
package main
import (
"fmt"
"time"
)
func main() {
start := time.Now()
fmt.Println("Hello World")
stop := time.Now()
duration := stop.Sub(start)
fmt.Printf("Time start|duration|stop: %v|%v|%v\n", start, duration, stop)
}
That's all about time package in Go.