Array.filter vs lodash filter

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.3.1/lodash.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var values = [];
   
    for (var i = 0; i < 100; i++) {
      values.push(i);
    }
   
    function isEven(value) {
      return (value % 2 === 0);
    }
};
</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
lodash
var result = _.filter(values, isEven);
pending…
Array.filter
var result = values.filter(isEven);
pending…
for optimized
var result = [];
for (var i = 0, c = values.length; i < c; ++i) {
   if (values[i] % 2 === 0) {
       result.push(values[i]);
   }
}
 
pending…
for
var result = [];
for (var i = 0; i < values.length; i++) {
   if (values[i] % 2 === 0) {
       result.push(values[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