Join Nostr
2024-11-09 16:18:19 UTC
in reply to

binaryphile on Nostr: A rule of thumb I use is if the number of operands is static, the + operator is ...

A rule of thumb I use is if the number of operands is static, the + operator is fastest because it takes advantage of knowing the length of the operands and can generate the result without having to loop and expand without knowing the target length. The benchmarks I've seen and tried bear this out. If the number of operands isn't static, you need to loop, in which case strings.Builder is the way to go. I found this post illuminating:

https://blog.calvinxiao.com/performance/2021/05/06/why-go-string-plus-fast.html