clone small array

JavaScript performance comparison

Revision 4 of this test case created by pooty

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = [0,1,2,3,4,5];
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
concat clone
var b = a.concat([]);
 
pending…
slice clone
var b = a.slice(0);
pending…
foreach clone
var b = [];
for( var i=0, l = a.length; i < l; i++ ){
    b[i] = a[i];
}
pending…
foreach clone, presized
var l = a.length, b = new Array(l);
for( var i=0; i < l; i++ ){
    b[i] = a[i];
}
pending…
foreach clone, push
var b = [];
for( var i=0, l = a.length; i < l; i++ ){
    b.push(a[i]);
}
pending…
push
var b = [];
b.push.apply(b,a);
 
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. Here’s a list of current revisions for this page:

0 comments

Add a comment