blob: 40d4a95405cd8a6596507e77dc18907e67786c43 [file]
go test -bench=Foo -cpuprofile=default.pgo -timeout=30s
go test -bench=Foo -pgo=default.pgo -timeout=30s
! stdout 'FAIL'
-- main_test.go --
package main
import (
"testing"
)
var a int
func save(x int) {
a = x
}
func foo() {
for i := range yield1 {
defer save(i)
}
}
func yield1(yield func(int) bool) {
yield(1)
}
func BenchmarkFoo(b *testing.B) {
for i := 0; i < b.N; i++ {
foo()
}
if a != 1 {
b.Fatalf("a = %d; want 1", a)
}
}
-- go.mod --
module demo
go 1.24