Re:Why is processing a sorted array faster than an unsorted ...
by anonymous on Friday June 28, 2013 @07:50PM
(#5960939)
Interestingly, when written in C, gcc compiles the inner loop to (comments mine):
In effect, it's adding data[c] to sum, storing it in a register and storing the result back in sum if data[c] was larger than 128, all with no jumps except for the loop itself and that jump is mispredicted exactly once. I don't see why java's JIT can't do the same.
[ Parent
| on HN ]
Re:Why is processing a sorted array faster than an unsorted ...
by mtdewcmu on Friday June 28, 2013 @09:13PM
(#5961169)
In the answers to the original question, somebody mentioned that gcc will convert branches into conditional moves, but only at -O3. I never use -O3, because it's frequently slower than -O2. In another answer, somebody pointed out that the ternary operator always generates a conditional move, which I never knew.