underscore.js filter vs native (v19)

Revision 19 of this benchmark created 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.firstName.indexOf('200') === 0;
});
ready
native
boulder['native'] = contacts.filter(function(contact) {
  return contact.firstName.indexOf('200') === 0;
});
ready

Revisions

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