for vs slice-map

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ];
};
</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 b = (a || []).slice(0, 3).map(function(item) { return item + 1; });
pending…
for
var b = [];
for (var i = 0, size = 3, length = a.length; i < size && i < length; ++i) {
    b.push(a[i] + 1);
}
pending…
only map
var b = (a || []).map(function(item, i) { return i < 3 ? item + 1 : undefined; }); 
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