modernize: Use b.Loop (introduced in Go 1.24)

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski
2025-12-15 17:51:24 +01:00
parent 239a49d403
commit c9b0a21bb1
15 changed files with 40 additions and 41 deletions

View File

@@ -8,7 +8,7 @@ import (
func BenchmarkGetTotalUsedFds(b *testing.B) {
ctx := context.Background()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = GetTotalUsedFds(ctx)
}
}

View File

@@ -287,8 +287,8 @@ func BenchmarkWrite(b *testing.B) {
data := []byte("Test line for testing stdwriter performance\n")
data = bytes.Repeat(data, 100)
b.SetBytes(int64(len(data)))
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
if _, err := w.Write(data); err != nil {
b.Fatal(err)
}

View File

@@ -184,7 +184,7 @@ func TestBytesPipeWriteRandomChunks(t *testing.T) {
func BenchmarkBytesPipeWrite(b *testing.B) {
b.ReportAllocs()
testData := []byte("pretty short line, because why not?")
for i := 0; i < b.N; i++ {
for b.Loop() {
readBuf := make([]byte, 1024)
buf := New()
go func() {
@@ -203,7 +203,7 @@ func BenchmarkBytesPipeWrite(b *testing.B) {
func BenchmarkBytesPipeRead(b *testing.B) {
b.ReportAllocs()
rd := make([]byte, 512)
for i := 0; i < b.N; i++ {
for b.Loop() {
b.StopTimer()
buf := New()
for j := 0; j < 500; j++ {

View File

@@ -145,8 +145,8 @@ func BenchmarkUnbuffered(b *testing.B) {
buf.WriteString(testLine)
testText := buf.Bytes()
b.SetBytes(int64(5 * len(testText)))
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
b.StopTimer()
setUpWriter()
b.StartTimer()