13 lines
329 B
Go
13 lines
329 B
Go
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
|
|
}
|