Sort Long List VS 10 Shorter Lists

JavaScript performance comparison

Revision 2 of this test case created by Marc Breuer

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var long = [], short = [];
  var shortCount = 100;
  for(var i=0;i<shortCount;i++){
  short.push([]);
  }
  
  var data = [];
  for(var i=0;i<10000;i++){
  data.push(Math.random());
  }

};
</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
Long List
var len = data.length;
for(var i=0;i<len;i++){
long.push(data[i]);
}
long.sort();
pending…
50 Short Lists
var len = data.length;
for(var i=0;i<len;i++){
var val = data[i];
short[~~(val*50)].push(val);
}
for(var i=0;i<50;i++){
short[i].sort();
}
pending…
10 Short Lists
var len = data.length;
for(var i=0;i<len;i++){
var val = data[i];
short[~~(val*10)].push(val);
}
for(var i=0;i<10;i++){
short[i].sort();
}
pending…
100 Short Lists
var len = data.length;
for(var i=0;i<len;i++){
var val = data[i];
short[~~(val*100)].push(val);
}
for(var i=0;i<100;i++){
short[i].sort();
}
pending…
20 Short Lists
var len = data.length;
for(var i=0;i<len;i++){
var val = data[i];
short[~~(val*20)].push(val);
}
for(var i=0;i<20;i++){
short[i].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