Description
· Each browser test results in a different data. For example, I use the chrome test General fast sort will be fastest, IE is based on the length of the array is likely to hill the fastest.
· Don't test bubble sort with too much data (browser crashes I don't care)
Personal understanding
· Bubble sort: Simplest, also slowest, seemingly length less than 7 optimal
· Insert sort: Faster than bubbling, slower than quick sort and hill sort, and smaller data has the advantage
· Quick sort: This is a very quick sort of way, V8 's sort method uses a combination of quick sort and insert sorting
· Hill sort: In non-chrome array length less than 1000, hill sort faster than fast
· System method: This method of Forfox system is very fast
- ----------some sort algorithms
- JS uses sort for sorting
- Systemsort:function (Array) {
- Return Array.Sort (function (A, b) {
- return a-b;
- });
- },
- Bubble sort
- Bubblesort:function (Array) {
- var i = 0, Len = array.length,
- J, D;
- for (; i<len; i++) {
- For (j=0 j<len; j + +) {
- if (Array[i] < array[j]) {
- d = array[j];
- ARRAY[J] = Array[i];
- Array[i] = D;
- }
- }
- }
- return array;
- },
- Quick Sort
- Quicksort:function (Array) {
- var array = [8,4,6,2,7,9,3,5,74,5];
- var array =
[0,1,2,44,4,324,5,65,6,6,34,4,5,6,2,43,5,6,62,43,5,1,4,51,56,76,7,7,2,1,45,4,6,7];
- var i = 0;
- var j = array.length-1;
- var Sort = function (i, j) {
- End condition
- if (i = = j) {return};
- var key = Array[i];
- var tempi = i; Record start position
- var tempj = j; Record End Position
- while (J > i) {
- J <<--------------look forward
- if (Array[j] >= key) {
- j--;
- }else{
- Array[i] = Array[j]
- i++------------>> Look Back
- while (J > ++i) {
- if (Array[i] > key) {
- ARRAY[J] = Array[i];
- Break
- }
- }
- }
- }
- If the first key to remove is the smallest number
- if (tempi = = i) {
- Sort (++i, TEMPJ);
- return;
- }
- Last vacancy left to key
- Array[i] = key;
- Recursion
- Sort (tempi, i);
- Sort (J, TEMPJ);
- }
- Sort (i, j);
- return array;
- },
- Insert Sort
- Insertsort:function (Array) {
- http://baike.baidu.com/image/d57e99942da24e5dd21b7080
- Http://baike.baidu.com/view/396887.htm
- var array =
[0,1,2,44,4,324,5,65,6,6,34,4,5,6,2,43,5,6,62,43,5,1,4,51,56,76,7,7,2,1,45,4,6,7];
- var i = 1, j, temp, Key,
- len = Array.Length;
- for (; i < Len; i++) {
- temp = j = i;
- key = Array[j];
- while (--j >-1) {
- if (Array[j] > key) {
- ARRAY[J+1] = Array[j];
- }else{
- Break
- }
- }
- ARRAY[J+1] = key;
- }
- return array;
- },
- Hill sort
- Jun.array.shellSort (JUN.ARRAY.DF (10000));
- Shellsort:function (Array) {
- Http://zh.wikipedia.org/zh/%E5%B8%8C%E5%B0%94%E6%8E%92%E5%BA%8F
- var array = [13,14,94,33,82,25,59,94,65,23,45,27,73,25,39,10];
- var Temparr = [1750, 701, 301, 132, 57, 23, 10, 4, 1];
- Reverse () See this optimal step size array on the wiki
- var Temparr = [1031612713, 217378076, 45806244,
- 9651787, 2034035, 428481, 90358, 19001, 4025, 836, 182, 34, 9, 1]
- Step selection for large arrays
- var i = 0;
- var temparrtemparrlength = temparr.length;
- var len = array.length;
- var len2 = parseint (LEN/2);
- for (; i < temparrlength; i++) {
- if (Temparr[i] > Len2) {
- Continue
- }
- Tempsort (Temparr[i]);
- }
- Sort one Step
- function Tempsort (temp) {
- Step statistics used by Console.log (temp)
- var i = 0, j = 0, F, tem, key;
- var Templen = len%temp > 0? parseint (len/temp) + 1:len/temp;
- for (; i < temp; i++) {//Loop columns sequentially
- For (J=1;/*j < Templen && */temp * j + i < Len; j + +) {
Loops each row of each column in turn
- TEM = F = Temp * j + i;
- key = Array[f];
- while ((tem-=temp) >= 0) {
- Look up in turn
- if (Array[tem] > key) {
- Array[tem+temp] = Array[tem];
- }else{
- Break
- }
- }
- Array[tem + temp] = key;
- }
- }
- }
- return array;
- }
Original link: http://www.cnblogs.com/idche/archive/2011/02/16/1956397.html
"Edit Recommendation"
- 10 amazing HTML5 and JavaScript effects
- JavaScript objects and the built-in objects of the inheritance tutorial
- JavaScript memory recovery mechanism in depth interpretation
- JavaScript beginners should pay attention to seven details
- wrote a continuous assignment operation that JavaScript may not fully understand for 10 years.
"Responsible editor: Chen Yu new TEL: (010) 68476606"