I had a sudden thought today and wanted to know whether the sort method has advantages over various sortings. This article mainly shares with you the difference between various sorting methods and sort methods based on js (detailed explanation), which has a good reference value. I hope to be helpful. Let’s follow the editor to take a look, I hope it can help everyone.
The above method passes the test time, and then analyzes which sorting method saves time. Time is life. Using the correct method can save a lot of time, especially when big data is running.
First look at the time it takes to process an array of 10,000 lengths:
* sort sorting systemSort 11
* bubble sorting bubbleSort 169
* quick sorting quickSort 144
* Insertion sorting insertSort 139
* Hill sorting shellSort 3
Test 100,000-long array data:
* sort sorting systemSort 63
* Bubble sorting bubbleSort 16268
* Quick sort quickSort reports an error directly
* Insertion sort insertSort 13026
* Hill sort shellSort 8
Test an array with a length of one million:
* sort sorting systemSort 575
* Bubble sort bubbleSort time is unknown
* Quick sort quickSort reports an error directly
* Insertion sort insertSort crashes directly
* Hill sort shellSort 93
Test 10 million long Array:
* sort sorting systemSort 7039
* Bubble sort bubbleSort not tested
* quick sort quickSort not tested
* insertion sort insertSort not tested
* Hill sorting shellSort 1225
Testing an array of 100 million long:
* sort sorting systemSort crashes directly
* Bubble sort bubbleSort not tested
* Quick sort quickSort not tested
* Insertion sort insertSort Not tested
* Hill sorting shellSort 19864
Finally passed the test. In the worst case, it was found that Hill sorting is still the best, and it is even faster than the system sorting. It is really surprising. In this way, everyone can see what method needs to be used for sorting under what circumstances, right?
Then we test in random situations:
Test a 10 million-long array:
* sort sorting systemSort 8842
* Bubble sorting bubbleSort not tested
* quick sort quickSort not tested
* insertion sort insertSort 45
* Hill sorting shellSort 1133
In unknown situations and relatively good situations, insertion sort is most efficient
Related recommendations:
Summary of PHP array sorting method
Detailed explanation of the use of sorting methods in javascript algorithms
Introduction to php array functions and summary of array sorting methods
The above is the detailed content of Detailed explanation of the differences between various js sorting methods and sort methods. For more information, please follow other related articles on the PHP Chinese website!