test1

JavaScript performance comparison

Test case created by dpaschal-lf

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var array = [1,2,3,4,5,6,7,8,9,10];

};

Benchmark.prototype.teardown = function() {
  var array = [1,2,3,4,5,6,7,8,9,10];

};
</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
insert
var output = [];
while(array.length){
   var spot = Math.floor( Math.random()*array.length);
   output.push ( array.splice(spot,1)[0]);
}
pending…
swap
for(var i = array.length-1; i>0; i--){
    var spot = Math.floor( Math.random() * i);
    var temp = array[i];
    array[i] = array[spot];
    array[spot] = temp;
}
pending…
swap with construct
for(var i = array.length-1; i>0; i--){
    var spot = Math.floor( Math.random() * i);
    [array[i], array[spot]] = [ array[spot], array[i] ];
}
pending…
random using sort
var output = array.sort( function(){ return .5 - Math.random();});
pending…

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

Compare results of other browsers

0 Comments