Use Go language to calculate the time consumed by a program to run:
Use the time package
import (
"time"
"fmt"
)
func function(){
startTime := time.Now()
...
待计时程序段
...
elapsedTime := time.Since(startTime) / time.Millisecond // duration in ms
fmt.Println("Segment finished in %dms", elapsedTime) //Segment finished in xxms
}
startTime can be used multiple times in different positions of the function, that is, the time consumed from starTime to different positions