Fastest 10 number sort

JavaScript performance comparison

Test case created by Daniel

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function sortNet10(data) {
    var swap;
    if (data[0] > data[5]) {
      swap = data[0];
      data[0] = data[5];
      data[5] = swap;
    }
    if (data[1] > data[6]) {
      swap = data[1];
      data[1] = data[6];
      data[6] = swap;
    }
    if (data[2] > data[7]) {
      swap = data[2];
      data[2] = data[7];
      data[7] = swap;
    }
    if (data[3] > data[8]) {
      swap = data[3];
      data[3] = data[8];
      data[8] = swap;
    }
    if (data[4] > data[9]) {
      swap = data[4];
      data[4] = data[9];
      data[9] = swap;
    }
    if (data[0] > data[3]) {
      swap = data[0];
      data[0] = data[3];
      data[3] = swap;
    }
    if (data[5] > data[8]) {
      swap = data[5];
      data[5] = data[8];
      data[8] = swap;
    }
    if (data[1] > data[4]) {
      swap = data[1];
      data[1] = data[4];
      data[4] = swap;
    }
    if (data[6] > data[9]) {
      swap = data[6];
      data[6] = data[9];
      data[9] = swap;
    }
    if (data[0] > data[2]) {
      swap = data[0];
      data[0] = data[2];
      data[2] = swap;
    }
    if (data[3] > data[6]) {
      swap = data[3];
      data[3] = data[6];
      data[6] = swap;
    }
    if (data[7] > data[9]) {
      swap = data[7];
      data[7] = data[9];
      data[9] = swap;
    }
    if (data[0] > data[1]) {
      swap = data[0];
      data[0] = data[1];
      data[1] = swap;
    }
    if (data[2] > data[4]) {
      swap = data[2];
      data[2] = data[4];
      data[4] = swap;
    }
    if (data[5] > data[7]) {
      swap = data[5];
      data[5] = data[7];
      data[7] = swap;
    }
    if (data[8] > data[9]) {
      swap = data[8];
      data[8] = data[9];
      data[9] = swap;
    }
    if (data[1] > data[2]) {
      swap = data[1];
      data[1] = data[2];
      data[2] = swap;
    }
    if (data[3] > data[5]) {
      swap = data[3];
      data[3] = data[5];
      data[5] = swap;
    }
    if (data[4] > data[6]) {
      swap = data[4];
      data[4] = data[6];
      data[6] = swap;
    }
    if (data[7] > data[8]) {
      swap = data[7];
      data[7] = data[8];
      data[8] = swap;
    }
    if (data[1] > data[3]) {
      swap = data[1];
      data[1] = data[3];
      data[3] = swap;
    }
    if (data[4] > data[7]) {
      swap = data[4];
      data[4] = data[7];
      data[7] = swap;
    }
    if (data[2] > data[5]) {
      swap = data[2];
      data[2] = data[5];
      data[5] = swap;
    }
    if (data[6] > data[8]) {
      swap = data[6];
      data[6] = data[8];
      data[8] = swap;
    }
    if (data[2] > data[3]) {
      swap = data[2];
      data[2] = data[3];
      data[3] = swap;
    }
    if (data[4] > data[5]) {
      swap = data[4];
      data[4] = data[5];
      data[5] = swap;
    }
    if (data[6] > data[7]) {
      swap = data[6];
      data[6] = data[7];
      data[7] = swap;
    }
    if (data[3] > data[4]) {
      swap = data[3];
      data[3] = data[4];
      data[4] = swap;
    }
    if (data[5] > data[6]) {
      swap = data[5];
      data[5] = data[6];
      data[6] = swap;
    }
    return (data);
  }
  
  var arr1 = [5, 7, 1, 8, 4, 3, 6, 9, 2, 0];
  var arr2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
  var arr3 = arr2.reverse();

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Network sort 2
sortNet10(arr2);
pending…
Network sort 3
sortNet10(arr3);
pending…
Standard sort 3
arr3.sort();
pending…
Network sort 1
sortNet10(arr1);
pending…
Standard sort 2
arr2.sort();
pending…
Standard sort 1
arr1.sort();
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments