HomePostsHow to measure execution time in Golang?

How to measure execution time in Golang?

May 25, 2022
0 minutes read

While developing Giraffe, I want to measure the execution time of the static files building process.

Here is the example code using time package:

start := time.Now()
 
// build process...
 
duration := time.Since(start)
fmt.Println("Duration:", duration)

or

start := time.Now()
 
// build process...
 
end := time.Now()
fmt.Println("Duration:", end.Sub(start))

Demo