I found String's "+" operation is so slowly on Go:
func main() {
start := time.Now();
s := ""
for i:=0;i<100000;i++ {
s += "test"
}
end := time.Now();
fmt.Println(end.Sub(start)) //Output 6.495225211s
}
But Python:
start = datetime.now()
s = ""
for i in range(100000):
s += 'test'
end = datetime.now()
print(end - start) # Output 0:00:00.020291
I know how to optimize the Go code. I hope you can tell me why.
thanks.
I found a interesting thing on Python:
s = ""
for i in range(20):
s += 'test'
print(id(s))
the output is:
139842066321960
139842066396912
139842066396912
139842066400072
139842066400072
139842067023232
139842067023232
139842066384304
139842066384304
139842066312528