package benchmarks

import "testing"

func BenchmarkSum10(b *testing.B)   { benchmarkSum(b, 10) }
func BenchmarkSum100(b *testing.B)  { benchmarkSum(b, 100) }
func BenchmarkSum1000(b *testing.B) { benchmarkSum(b, 1000) }

// 通用辅助函数，避免重复代码
func benchmarkSum(b *testing.B, size int) {
	// 提前造好数据，防止每次循环都分配
	nums := make([]int, size)
	for i := 0; i < size; i++ {
		nums[i] = i
	}
	b.ResetTimer() // 重置计时器，上面初始化不计入

	for i := 0; i < b.N; i++ {
		_ = Sum(nums...)
	}
}
