blob: 042e2980bb62104a6a0a591eb7f22dfbe4c7ef38 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
|
package main
import (
"time"
)
// timeFunction takes a function as an argument and returns the execution time.
func TimeFunction(f func()) time.Duration {
startTime := time.Now() // Record the start time
f() // Execute the function
return time.Since(startTime) // Calculate the elapsed time
}
|