2020-12-02
java – Why is processing a sorted array faster than processing an unsorted array?

The Question : 25053 people think this question is useful Here is a piece of C++ code that shows some very peculiar behavior. For some strange reason, sorting the data miraculously makes the code almost six times faster: Without std::sort(data, data + arraySize);, the code runs in 11.54 seconds. With the sorted data, the code