mirror of
https://github.com/teivah/100-go-mistakes.git
synced 2026-06-20 16:45:56 +08:00
26 lines
357 B
Go
26 lines
357 B
Go
package timer
|
|
|
|
import "testing"
|
|
|
|
func BenchmarkFoo1(b *testing.B) {
|
|
expensiveSetup()
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
functionUnderTest()
|
|
}
|
|
}
|
|
|
|
func BenchmarkFoo2(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
b.StopTimer()
|
|
expensiveSetup()
|
|
b.StartTimer()
|
|
functionUnderTest()
|
|
}
|
|
}
|
|
|
|
func functionUnderTest() {
|
|
}
|
|
|
|
func expensiveSetup() {
|
|
}
|