首次提交:初始化项目代码

This commit is contained in:
sunct
2026-07-31 15:18:32 +08:00
commit d6393266b0
193 changed files with 14287 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
package main
import (
"fmt"
"strings"
"time"
)
func main() {
const loopCount = 100000 // 10万次拼接
var builder strings.Builder
// 预分配内存(预估每个item占10字节,避免动态扩容)
builder.Grow(loopCount * 10)
start := time.Now()
for i := 0; i < loopCount; i++ {
fmt.Fprintf(&builder, "item_%d,", i) // 直接写入缓冲区,无临时字符串
}
result := builder.String()
fmt.Printf("strings.Builder拼接耗时:%v\n", time.Since(start))
_ = result // 避免未使用变量警告
}