2021
06-04
06-04
基于Go Int转string几种方式性能测试
Go语言内置int转string至少有3种方式:fmt.Sprintf("%d",n)strconv.Itoa(n)strconv.FormatInt(n,10)下面针对这3中方式的性能做一下简单的测试:packagegotestimport("fmt""strconv""testing")funcBenchmarkSprintf(b*testing.B){n:=10b.ResetTimer()fori:=0;i<b.N;i++{fmt.Sprintf("%d",n)}}funcBenchmarkItoa(b*testing.B){n:=10b.ResetTimer()fori:=0;i<b.N;i++{strconv.Itoa(n)}}f...
继续阅读 >