4 ms·
> its like the age-old "+" vs "strings.Builder" debate for concatenation that's not even a debate. Have you done tests on this? If I remember right, once the s
by svnpenn 4y ago
> its like the age-old "+" vs "strings.Builder" debate for concatenation
that's not even a debate. Have you done tests on this? If I remember right, once the string runs over the GC default (I think 1 GB), "+" turns from linear to exponential time. So yeah I guess for most stuff it doesn't matter, but when it does matter its a huge time difference
- traceroute66 4y ago> once the string runs over the GC default (I think 1 GB), Not wishing to sound snarky, but is there even a valid use-case for concatenating GB+ quantities of strings (or even hundreds of MB) ? I mean surely you'll (potentially) run into memory exhaustion issues and other fun things ?
- IshKebab 4y agoOf course there is. 1 GB is not even that big these days.
- MaxBarraclough 4y ago> Of course there is When? Why not use ropes and avoid the copy?
- svnpenn 4y agopersonally I don't see a need for it, but I'm sure someone will do something dumb that requires it
- HideousKojima 4y agoWhile not Go, in C# you can avoid a ton of heap allocations by using StringBuilder instead of concatenation, and the crossover point for one being more efficient than the other is at something like 4 concatenations. But people will always say nonsense about "premature optimization" the moment you care about performance.
- svnpenn 4y agoIn regards to Go, in most cases its a pointless optimization. Unless the string is quite large, its the same result. Go is nothing like C# in this case.
- makapuf 4y agoIn python since 2.5 (and im sure other languages implemntations) the compiler/implementation recognize this += use case and implement it as a fast one.