underscore lodash native (with polyfill) (v5)

Revision 5 of this benchmark created on


Description

updated to latest version

Preparation HTML

<script src="//www.cinsoft.net/mylib099-min.js"></script>

Setup

var arr = [1, 2, 3, 'test', 'anotherString', 1, 3, 98, 1, '', undefined, 'bla', 3];

Test runner

Ready to run.

Testing in
TestOps/sec
Underscore
underscore.find(arr, function(item) {
  return item === 'bla';
});
ready
Lodash
lodash.find(arr, function(item) {
  return item === 'bla'
});
ready
Native (MDN polyfill)
if (!Array.prototype.find) {
  Object.defineProperty(Array.prototype, 'find', {
    enumerable: false,
    configurable: true,
    writable: true,
    value: function(predicate) {
      if (this == null) {
        throw new TypeError('Array.prototype.find called on null or undefined');
      }
      if (typeof predicate !== 'function') {
        throw new TypeError('predicate must be a function');
      }
      var list = Object(this);
      var length = list.length >>> 0;
      var thisArg = arguments[1];
      var value;

      for (var i = 0; i < length; i++) {
        value = list[i];
        if (predicate.call(thisArg, value, i, list)) {
          return value;
        }
      }
      return undefined;
    }
  });
}

function findBla(element, index, array) {
  return element === 'bla';
}

arr.find(findBla);
ready

Revisions

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