Re:Why is it faster to process a sorted array than an unsort...
by rayiner on Friday September 15, 2017 @01:28PM
(#15259003)
The second loop will do O(N) comparisons. If the array is unsorted, each will be poorly predicted. The best possible comparison sort will do O(N * log(N)) comparisons. If the array is unsorted, each of those will be poorly predicted. So regardless of the pipeline length, sorting first will be strictly slower than operating on the unsorted data. Sorting first might help if you subsequently need to do something that will do more than O(N * log(N)) comparisons.
[ Parent
| on HN ]
There are no comments on this comment yet.