for vs lodash find

JavaScript performance comparison

Test case created by OSM Buildings and last updated

Preparation code

<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.0.0-rc.3/lodash.min.js"></script>

<script>
  var media = [];
  var types = [123, 666, 999, 'test', 'hello', 'bar', 0];
  for (var i = 0; i < 100; i++) {
    media[i] = {
      name: i,
      type: types
    };
  }
  media[50].type = types.concat('foo');
</script>
<script>
Benchmark.prototype.setup = function() {
    var type = 'foo';
    var result;
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
for
for (var i = 0, len = media.length; i < len; i++) {
  if (~media[i].type.indexOf(type)) {
    result = media[i];
    break;
  }
}
pending…
lodash find
result = _.find(media, function(source) {
  return ~_.indexOf(source.type, type);
});
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