Why is processing a sorted array faster than an unsorted array?(stackoverflow.com)
stackoverflow.com
Why is processing a sorted array faster than an unsorted array?
http://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-an-unsorted-array
3 comments
Java 3.326788s, C++ 8.46879s on my machine. This is interesting. Code seems analogous.
Code in the question is a bad test example. As the answer shows, different compilers can optimize the code in different ways to make the outer loop almost meaningless. A better test would have 100000 different arrays to test.
Did you enable optimizations in C++ and disable adaptive optimization in java?
Did you enable optimizations in C++ and disable adaptive optimization in java?
https://www.hnsearch.com/search#request/submissions&q=Why+is...
Discussion: https://news.ycombinator.com/item?id=4637196