package src_test

import (
	"strings"
	"testing"
)

// section: basic
func BenchmarkStringConcat(b *testing.B) {
	for i := 0; i < b.N; i++ {
		s := ""
		for j := 0; j < 100; j++ {
			s += "a"
		}
	}
}

// section: basic

// section: loop
func BenchmarkStringBuilder_Loop(b *testing.B) {
	// Setup runs exactly once with B.Loop()
	parts := make([]string, 100)
	for i := range parts {
		parts[i] = "a"
	}

	// Use b.Loop() instead of for i := 0; i < b.N; i++
	for b.Loop() {
		var sb strings.Builder
		for _, p := range parts {
			sb.WriteString(p)
		}
		_ = sb.String()
	}
}

// section: loop

// section: compare
func BenchmarkStringJoin_Loop(b *testing.B) {
	parts := make([]string, 100)
	for i := range parts {
		parts[i] = "a"
	}

	for b.Loop() {
		_ = strings.Join(parts, "")
	}
}

// section: compare
