1.1 fmt  vs  "+" (无转义)

import (
    "testing"
    "fmt"
)

var (
    str = "hello gohpers!"
    sep = ","
)

func BenchmarkFmt(b *testing.B) {
    for i := 0; i < b.N; i++ {
        _ = fmt.Sprint("%s%s%s%s%s", str, sep, str, sep, str)
    }
}

func BenchmarkPlus(b *testing.B) {
    for i := 0; i < b.N; i++ {
        _ = str + sep + str + sep + str
    }
}

运行结果概括如下:

BenchmarkFmt        3000000	       490 ns/op
BenchmarkPlus        15000000	        78 ns/op

1.1 fmt  vs  "+" (带有转义)

 

2. strings.join  VS  "+"

持续更新中

 

相关文章:

  • 2022-12-23
  • 2021-10-26
  • 2021-10-28
  • 2022-01-07
  • 2022-01-17
  • 2022-01-26
  • 2022-01-27
  • 2021-06-11
猜你喜欢
  • 2021-09-27
  • 2021-06-06
  • 2022-01-10
  • 2022-12-23
  • 2022-01-13
  • 2021-08-04
  • 2022-01-10
相关资源
相似解决方案