4 ms·
I was with you until you got to the ++x/x++ example. It is a bad example because they generate the same machine code except in situations where they are semanti
by benchaney 9y ago
I was with you until you got to the ++x/x++ example. It is a bad example because they generate the same machine code except in situations where they are semantically different.
- mark-r 9y agoFor simple types that's true, and that's part of the 99% I was talking about. Where it makes a difference is class types, C++ iterators being a prime example. Maybe the optimizer can make the two cases generate identical code, but why take the chance? I chose that example because it didn't need a full paragraph to explain, but you're right that there are probably better ones. Edit: maybe a Python example? ''.join([a, b, c]) is faster than a + b + c, but again 99% of the time you won't be using it in performance critical code. But it's a useful idiom to know.
- jacobolus 9y agoFrom what I remember, for such small examples, a + b + c is significantly faster. (The CPython folks might have done some optimization work on this a few years back?) It’s only if you plan to concatenate a whole lot of strings that join is a clear winner.