W3Ask






HOME  >  PROGRAMMING  >  GLOBAL PROGRAMMING

Sorted array faster than unsorted array




With the following line in a loop, the code will be executed ten times faster than without.

The goal of this code is to determine first the conditions that will be false and then those that will be true. It helps to predict (branch prediction) the future outcome, decreasing the memory load. Whereas without the sorted array, the code has to determine the consequence of the conditon for every value.

std::sort(data, data + arraySize);








Related posts:


No related posts.