In this section, you are going to learn how to measure the execution time of one or more commands in Go. The same technique can be applied for measuring the execution time of a function or a group of functions. The name of the Go program is execTime.go and it will be presented in three parts.
This is an easy-to-implement technique that is both very powerful and handy. Do not underestimate the simplicity of Go.
The first part of execTime.go is as follows:
package main import ( "fmt" "time" ) func main() { start := time.Now() time.Sleep(time.Second) duration := time.Since(start) fmt.Println("It took time.Sleep(1)", duration, "to finish.")
You will need the functionality offered by the time package in order to measure the execution time of a command. All the job is done by the...