测试了三个从数字转换为字符的性能,

高手的感觉。。。。

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)
	}
}

  Go语言的基准测试简单示例

相关文章:

  • 1970-01-01
  • 2022-02-13
  • 2022-12-23
  • 2021-11-19
  • 2022-01-23
  • 2021-11-16
猜你喜欢
  • 2021-05-29
  • 2019-03-21
  • 2022-12-23
  • 2023-02-05
  • 2021-07-09
  • 2022-12-23
  • 2021-08-06
相关资源
相似解决方案