func BenchmarkMyFunction(b *testing.B) { for i := 0; i < b.N; i++ { b.ResetTimer() MyFunction() } }
func BenchmarkMyFunction(b *testing.B) { for i := 0; i < b.N; i++ { MySetupFunction() b.ResetTimer() MyFunction() } }In this example, we have a setup function called "MySetupFunction" that needs to be run before each iteration of the benchmark. We want to exclude the setup time from our measurement, so we reset the timer after the setup function is called and before the main function is called. The package library for ResetTimer is "testing" as it is part of the Go testing package.