Golang: measure time to execute code

Sometimes you want to know how long it takes to execute a piece of code. This is how to do it Golang:

func main() {
start := time.Now()

// Do something time consuming

elapsed := time.Since(start)
log.Printf(“Time to execute code %s”, elapsed)
}

 

Leave a Reply

Your email address will not be published.