clone array

JavaScript performance comparison

Revision 2 of this test case created by Tyler Young

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31];
};
</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…

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