in reply to Re^2: does perl have branch prediction
in thread does perl have branch prediction

How can we explain the small time difference between the sorted and unsorted array summing?

It is almost certainly down to the cpu instruction cache.

  1. With the sorted array, on average:

    for the first half of the array, the instructions required in the loop will already be in the cache.

    Then there will be a need to load the required instructions into the cache, once, when the break point is reached, and they will remain there for the second half of the array.

  2. With the unsorted array,

    the instruction cache potentially might need to be flushed and repopulated for every other iteration of the loop.

Please note, that is just my best guess. I can't think of any easy -- or even feasible given what hardware and software I have available to me -- way of attempting to verify my hypothesis.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.