angular forEach vs lodash findIndex

Benchmark created by Pushpak Rangaiah on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>

Setup

var findID = 33,
      dataset = [{
        "id": 37,
        "hash": "c7c0352617e0e4547d4aeb80f7819519",
        "name": "Dove",
        "section": "General",
        "qty": 1,
        "rate": 20
      }, {
        "id": 36,
        "hash": "00cbf9ea093a3dfb0867af1c2691ac42",
        "name": "Masala Tea",
        "section": "General",
        "qty": 1,
        "rate": 20
      }, {
        "id": 35,
        "hash": "fb2fa00172305cc013cb984af0166199",
        "name": "Composite Item",
        "section": "General",
        "qty": 1,
        "rate": 69
      }, {
        "id": 34,
        "hash": "fe6d4b066d6ae433bd8d33834f278763",
        "name": "Coffee",
        "section": "General",
        "qty": 1,
        "rate": 15
      }, {
        "id": 33,
        "hash": "9b7ac80eea1bbd2f27059aea9909d4b4",
        "name": "Masala Dosa",
        "section": "General",
        "qty": 1,
        "rate": 45
      }, {
        "id": 32,
        "hash": "cb26002fefafb5e147835ba6b4d1e870",
        "name": "teststocktrack",
        "section": "General",
        "qty": 1,
        "rate": 99
      }];

Test runner

Ready to run.

Testing in
TestOps/sec
angular forEach
angular.forEach(dataset, function(pdata, index) {
  if (pdata.id == findID) {

  }
});
ready
lodash findIndex
_.findIndex(dataset, {
  "id": Number(findID)
});
ready

Revisions

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

  • Revision 1: published by Pushpak Rangaiah on