I have a loop that adds up every element of a 32,768-element array whose value is 128 or more: if (data[i] >= 128) sum += data[i];. The values are random bytes from 0 to 255. If I sort the array first, the loop runs several times faster, even though it executes exactly the same number of comparisons and additions.
What makes sorted data faster for the processor, and why do some people report no difference at all when they try to reproduce this?




