Performance of BinaryHeap::into_sorted_vec
vs. Vec::sort_unstable
#115357
Labels
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
C-optimization
Category: An issue highlighting optimization opportunities or PRs implementing such
I-slow
Issue: Problems and improvements with respect to performance of generated code.
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
I think the implementation of
BinaryHeap::into_sorted_vec
should just useVec::sort_unstable
instead of sorting by repeated Heap operations. For very small N (N < 1000), the current implementation is maybe 5% faster some times, but for bigger NVec::sort_unstable
will be more than 10 to 30 times faster.Also, I assume sorting by Heap operations requires 2*N*Log2(N) key comparisons in average and worst case when using the default Heapsort like in the standard library, while
Vec::sort_unstable
probably requires less than 1.5*N*Log2(N) key comparisons in average case and also a lower number of moves in average case.I don't have good statistics, maybe others could add some.
Here is an example, to show the performance difference:
The text was updated successfully, but these errors were encountered: