News for hackers. Stuff that matters.
Re:Why is this C++ code faster than my hand-written assembly... by benchaney on Tuesday August 22, 2017 @01:57PM (#15074858)
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.
Re:Why is this C++ code faster than my hand-written assembly... by mark-r on Tuesday August 22, 2017 @02:14PM (#15075013)
For 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.

Re:Why is this C++ code faster than my hand-written assembly... by jacobolus on Wednesday August 23, 2017 @02:12AM (#15078949)
From 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.