Array.prototype.filter vs plain loop

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var t = [{k:2, v:"Stack"}, {k:5, v:"Over"}, , {k:9, v:"flow"}];
   
    var r = [];
};
</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
Array.prototype.filter
r = t.filter(function (elem) {
    return elem.k <= 5;
});
pending…
plain loop
for (var i = 0, l = t.length;i<=l;i++){
   if(t[i] && t[i].k <= 5){r.push(t[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