First x elements: slice vs length

JavaScript performance comparison

Revision 41 of this test case created

Info

Comparing runtimes of length and slice for decreasing array size.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var bigArray = [];
    // Large = 100,000
    for (var i = 0; i < 100000; i++) {
      bigArray.push(i % 42);
    }
};
</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
Slice
var bigArray2 = bigArray.slice(0);
bigArray2.slice(0, 100);
pending…
Length
var bigArray2 = bigArray.slice(0);
bigArray2.length = 100;
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