外观
约 100 字小于 1 分钟
2025-09-04
将原语转换为字符串或从字符串转换时,strconv速度比fmt快。
strconv
fmt
for i := 0; i < b.N; i++ { s := fmt.Sprint(rand.Int()) }
for i := 0; i < b.N; i++ { s := strconv.Itoa(rand.Int()) }
BenchmarkFmtSprint-4 143 ns/op 2 allocs/op
BenchmarkStrconv-4 64.2 ns/op 1 allocs/op
a059b