测试
1 | package performance_test |
go test -v -test.bench=”.” -benchmem String_concatenation_test.go
1 | goos: darwin |
结论
- fmt.Sprintf 和 strings.Join 速度相当
- string + 比上述二者快一倍
- bytes.Buffer又比上者快约400-500倍
1 | package performance_test |
go test -v -test.bench=”.” -benchmem String_concatenation_test.go
1 | goos: darwin |