javascript sort qsort

Benchmark created on


Preparation HTML

<script>
  var a=[];
  for(var i=0;i<10000;i++){
      a.push(parseInt(10000*Math.random()));
  }
  
  Array.prototype.qsort=function(low, high){
      var i=low;
      var j=high;
      var a=this[i];
      if(low<high){
          while(i<j){
              while(i<j && this[j]>a){ j--; }
              if(i<j){
                  this[i]=this[j];
                  i++;
              }
              while(i<j && this[i]<a){ i++; }
              if(i<j){
                  this[j]=this[i];
                  j--;
              }
          }
          this[i]=a;
          this.qsort(low,i-1);
          this.qsort(i+1,high);
      }
      return this;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
native sort
a.sort(function(i,j){return i-j;});
ready
quick sort
a.qsort(0,a.length-1);
ready

Revisions

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