0
1
mirror of https://github.com/golang/go synced 2024-12-03 14:35:57 +00:00
go/test/inline_testingbloop.go
Junyang Shao 558f5372fc cmd/compile,testing: implement one-time rampup logic for testing.B.Loop
testing.B.Loop now does its own loop scheduling without interaction with b.N.
b.N will be updated to the actual iterations b.Loop controls when b.Loop returns false.

This CL also added tests for fixed iteration count (benchtime=100x case).

This CL also ensured that b.Loop() is inlined.

For #61515

Change-Id: Ia15f4462f4830ef4ec51327520ff59910eb4bb58
Reviewed-on: https://go-review.googlesource.com/c/go/+/627755
Reviewed-by: Michael Pratt <mpratt@google.com>
Commit-Queue: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-11-20 23:19:48 +00:00

38 lines
1.1 KiB
Go

// errorcheck -0 -m=2
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Test no inlining of function calls in testing.B.Loop.
// See issue #61515.
package foo
import "testing"
func caninline(x int) int { // ERROR "can inline caninline"
return x
}
func cannotinline(b *testing.B) { // ERROR "b does not escape" "cannot inline cannotinline.*"
for i := 0; i < b.N; i++ {
caninline(1) // ERROR "inlining call to caninline"
}
for b.Loop() { // ERROR "skip inlining within testing.B.loop" "inlining call to testing\.\(\*B\)\.Loop"
caninline(1)
}
for i := 0; i < b.N; i++ {
caninline(1) // ERROR "inlining call to caninline"
}
for b.Loop() { // ERROR "skip inlining within testing.B.loop" "inlining call to testing\.\(\*B\)\.Loop"
caninline(1)
}
for i := 0; i < b.N; i++ {
caninline(1) // ERROR "inlining call to caninline"
}
for b.Loop() { // ERROR "skip inlining within testing.B.loop" "inlining call to testing\.\(\*B\)\.Loop"
caninline(1)
}
}