concat-pop-vs-length

JavaScript performance comparison

Revision 4 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var items = [];
    for (var i = 0, length = 10000; i < length; i++) {
      items[i] = i;
    }
};
</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 shift
var result = 0;
var copy = items.concat();
for ( var i = 0, length = items.length; i < length; i++ ){
 result += copy.shift();
}
pending…
while length
var result = 0;
var copy = items.concat();
for ( var i = 0, length = items.length; i < length; i++ ){
 result += copy[i];
}
pending…
concat pop
var result = 0;
var copy = items.concat();
for ( var i = 0, length = items.length; i < length; i++ ){
 result += copy.pop();
}
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