标签:blog com highlight src printf ges itoa alt 数字转换
测试了三个从数字转换为字符的性能,
高手的感觉。。。。
package listing28_test
import (
"fmt"
"testing"
"strconv"
)
func BenchmarkSprintf(b *testing.B) {
number := 10
b.ResetTimer()
for i := 0; i < b.N; i++ {
fmt.Sprintf("%d", number)
}
}
func BenchmarkFormat(b *testing.B) {
number := int64(10)
b.ResetTimer()
for i := 0; i < b.N; i++ {
strconv.FormatInt(number, 10)
}
}
func BenchmarkItoa(b *testing.B) {
number := 10
b.ResetTimer()
for i := 0; i < b.N; i++ {
strconv.Itoa(number)
}
}

标签:blog com highlight src printf ges itoa alt 数字转换
原文地址:http://www.cnblogs.com/aguncn/p/7102767.html