Differences between js sorting methods and sort methods (detailed description), jssort

Source: Internet
Author: User

Differences between js sorting methods and sort methods (detailed description), jssort

Today, I was wondering if the sort method is better than sorting. So I started a test by referring to other people's code, and the results were surprising.

<! DOCTYPE html> 

The above method passes the test time, and then analyzes which sorting method saves time and time is life. Using the correct method can save a lot of time, especially when big data is running.

First, let's take a look at the time used to process an array of 10000 lengths:

* Sort systemSort 11 by sort
* Bubble Sorting bubbleSort 169
* Quick sorting 144
* Insert the sorting insertSort 139.
* ShellSort 3

Test the 100,000 long array data:

* Sort systemSort 63
* Bubble Sorting bubbleSort 16268
* Quick sorting directly reports an error
* Insert the sorting insertSort 13026.
* ShellSort 8 by hill

Test the length of an array of 1 million:

* Sort systemSort 575
* The time for bubbleSort in Bubble Sorting is unknown.
* Quick sorting directly reports an error
* Insert sort insertSort directly crashes
* ShellSort 93

Test an array with a length of 10 million:

* Sort systemSort 7039
* The Bubble Sorting bubbleSort is not tested.
* Quick sorting is not tested
* InsertSort not tested
* ShellSort 1225 by hill

Test an array with a length of 0.1 billion:

* The sort systemSort directly crashes.
* The Bubble Sorting bubbleSort is not tested.
* Quick sorting is not tested
* InsertSort not tested
* ShellSort 19864 by hill

Finally, pass the test,In the worst caseWe are surprised to find that the hill sorting is still the best, and it is faster than the system's sort sorting. In this way, we can see what sort methods are needed.

Then we conduct a random test:

<! DOCTYPE html> 

Test an array with a length of 10 million:

* Sort systemSort 8842
* The Bubble Sorting bubbleSort is not tested.
* Quick sorting is not tested
* Insert sorting insertSort 45
* ShellSort 1133 by hill

Insert sorting is most efficient in unknown and better cases.

The above differences based on various js sorting methods and sort methods (detailed description) are all the content that I have shared with you. I hope to give you a reference and support for more.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.