underscore.js filter vs native (v8)

Revision 8 of this benchmark created by Hugo Campos on


Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>

Setup

window.contacts = [];
    
    var contact;
    
    function getRandomInt (min, max) {
      return Math.floor(Math.random() * (max - min + 1)) + min;
    }
    
    for (var i=0; i < 5000; i++) {
      contact = {};
      contact.firstName = 'firstName' + getRandomInt(1, 500);
      contact.lastName = 'lastName' + getRandomInt(1, 500);
      contact.city = ["Boulder", "Denver", "Denver", "Golden"][getRandomInt(0, 3)];
      contact.state = "CO";
      contacts.push(contact);
    }
    
    var boulder = window.boulder = window.boulder || {};

Test runner

Ready to run.

Testing in
TestOps/sec
underscore
boulder['underscore'] = _.filter(contacts, function(contact) {
  return contact.city === 'Boulder';
});
ready
native
boulder['native'] = contacts.filter(function(contact) {
  return contact.city === 'Boulder';
});
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.