package main import ( "fmt" "time" ) type FuncType func() func main() { time := runFuncByConsumptionTime(test) fmt.Printf("The consumption time is:%d ms \\n", time) } func test() { time.Sleep(1*time.Second) } func runFuncByConsumptionTime(callback FuncType) int64 { start := time.Now().UnixNano() / 1e6 callback() end := time.Now().UnixNano() / 1e6 return end - start }