Script Preparation code:
AخA
 
var testObject = {};
testObject.eligibilityGroupDates = [{
    "id": "8c7969fd-56db-4ed8-9eec-5604c3dceef7",
    "o2eStartDate": "scrub1",
    "numOfDaysToCalO2EStartDate": null,
    "numberOfDaysToEnroll": 99,
    "eligibilityGroups": ["f32e6a9f-4a4b-4531-af8f-4e4ee0798e91"],
    "links": []
}, {
    "id": "7dc6052d-7ede-452a-8425-604c24c3d561",
    "o2eStartDate": "scrub2",
    "numOfDaysToCalO2EStartDate": 58,
    "numberOfDaysToEnroll": 95,
    "eligibilityGroups": ["f9987b9a-f45a-4131-8528-47242023483e"],
    "links": []
}, {
    "id": "af886791-fb79-4d28-921c-539cdaadae79",
    "o2eStartDate": "scrub2",
    "numOfDaysToCalO2EStartDate": null,
    "numberOfDaysToEnroll": 30,
    "eligibilityGroups": ["927a5c93-368c-4a82-a6d3-99e656624978"],
    "links": []
}];
Tests:
  • using loop

     
        if (_.has(testObject, 'eligibilityGroupDates')) {
          testObject.eligibilityGroupDates.forEach(entry => {
            Object.keys(entry).forEach(key => {
              switch (key) {
                case 'eligibilityGroupDates':
                  _.set(testObject, 'displayEligibilityGroupDates', true);
                  break;
                case 'o2eStartDate':
                  _.set(testObject, 'displayO2eStartDate', true);
                  break;
                case 'numOfDaysToCalO2EStartDate':
                  _.set(testObject, 'displayNumOfDaysToCalO2EStartDate', true);
                  break;
                case 'numberOfDaysToEnroll':
                  _.set(testObject, 'displayNumberOfDaysToEnroll', true);
                  break;
                default:
                  break;
              }
            });
          });
        }
  • using JSON stringify

     
        if (_.has(testObject, 'eligibilityGroupDates')) {
          let value = JSON.stringify(testObject.eligibilityGroupDates);
          if (value.indexOf('eligibilityGroups') > 0) {
            _.set(testObject, 'eligibilityGroups', true);
          }
          if (value.indexOf('o2eStartDate') > 0) {
            _.set(testObject, 'displayO2eStartDate', true);
          }
          if (value.indexOf('numOfDaysToCalO2EStartDate') > 0) {
            _.set(testObject, 'displayNumOfDaysToCalO2EStartDate', true);
          }
          if (value.indexOf('numberOfDaysToEnroll') > 0) {
            _.set(testObject, 'displayNumberOfDaysToEnroll', true);
          }
        }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    using loop
    using JSON stringify

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:106.0) Gecko/20100101 Firefox/106.0
Firefox 106 on Windows
View result in a separate tab
Test name Executions per second
using loop 318245.2 Ops/sec
using JSON stringify 281773.3 Ops/sec