package main import( "fmt" "time" "bytes" "strings" ) var loop = 100000 func
main(){ var s string s1 := "hello" s2 := "world" var start time.Time // plus + connect
start= time.Now() for i := 0; i<loop; i++{ s1 += s2 } fmt.Println("+ Connection method :",time.
Since(start)) //append connect s1 = "hello" s2 = "world" start = time.Now() for i := 0
; i<loop; i++{ s = string(append([]byte(s1),s2...)) } fmt.Println("append method :",
time.Since(start)) //Join Method connection v := []string{"hello","world"} start = time.Now()
for i := 0; i<loop; i++{ s = strings.Join(v,"") } fmt.Println("strings.Join method :",
time.Since(start)) //bytes.writestring method start = time.Now() for i := 0; i<loop;
i++{ var buf bytes.Buffer buf.WriteString("hello") buf.WriteString("world") buf.
String() } fmt.Println("bytes.writestring method :",time.Since(start)) //fmt Method connection start
= time.Now() for i := 0; i<loop; i++{ s = fmt.Sprintf("%s%s","hello","world") }
fmt.Println("fmt method :",time.Since(start)) fmt.Println(s) }
output
+ Connection method : 4.1359933s append method : 3.0201ms strings.Join method : 3.9848ms
bytes.writestring method : 5.0207ms fmt method : 10.9764ms helloworld
Efficiency ranking :
append> strings.Join() > + > bytes.writestring > fmt

Technology