Skip to content

Measure execution time

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

Here is the example code using time package:

go
start := time.Now()

// build process...

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

// build process...

duration := time.Since(start)
fmt.Println("Duration:", duration)

or

go
start := time.Now()

// build process...

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

// build process...

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

Demo