refactor: use b.Loop() in benchmark tests for better performance (#25461)

Signed-off-by: wyrapeseed <wyrapeseed@outlook.com>
Co-authored-by: Alex | Cosmos Labs <alex@cosmoslabs.io>
This commit is contained in:
wyrapeseed 2025-10-16 01:25:46 +08:00 committed by GitHub
parent 72c71c3fa8
commit abc305483d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 3 additions and 4 deletions

View File

@ -56,9 +56,8 @@ func TestNewAnyWithCustomTypeURLWithErrorNoAllocation(t *testing.T) {
var sink any
func BenchmarkNewAnyWithCustomTypeURLWithErrorReturned(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for b.Loop() {
any, err := types.NewAnyWithValue(eom)
if err == nil {
b.Fatal("err wasn't returned")

View File

@ -52,7 +52,7 @@ func (s *StringSuite) TestUnsafeBytesToStr() {
}
func BenchmarkUnsafeStrToBytes(b *testing.B) {
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
UnsafeStrToBytes(strconv.Itoa(i))
}
}

View File

@ -52,7 +52,7 @@ func (s *StringSuite) TestUnsafeBytesToStr() {
}
func BenchmarkUnsafeStrToBytes(b *testing.B) {
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
UnsafeStrToBytes(strconv.Itoa(i))
}
}