Loop Performance

Benchmark created on


Description

Setup

const documents = [
  {
    amount: "100",
    expectedTime: "30 minutes",
    dateSigned: "2023-01-15T10:20:30.000Z"
  },
  {
    amount: "200",
    expectedTime: "45 minutes",
    dateSigned: "2023-05-22T14:50:00.000Z"
  },
  {
    amount: "150",
    expectedTime: "60 minutes",
    dateSigned: "2023-08-10T08:15:45.000Z"
  },
  {
    amount: "250",
    expectedTime: "90 minutes",
    dateSigned: "2023-11-30T16:40:20.000Z"
  },
  {
    amount: "300",
    expectedTime: "120 minutes",
    dateSigned: "2024-02-18T12:00:00.000Z"
  }
]

const currentDate = new Date();
let hasDocumentsSignedBeforeLimitDate = false;

Test runner

Ready to run.

Testing in
TestOps/sec
_forEach
_.forEach(documents, (document) => {
  const signedDate = new Date(document.dateSigned);
  const limitDate = new Date(currentDate.getFullYear(), 7, 1);

  if (signedDate < limitDate && currentDate >= limitDate) {
    hasDocumentsSignedBeforeLimitDate = true;
  } else if (signedDate >= limitDate) {
    return false;
  }

  if (isNaN(new Date(document.dateSigned)) && currentDate >= limitDate) {
    hasDocumentsSignedBeforeLimitDate = true;
  }
});
ready
For loop
for (const document of documents) {
  const signedDate = new Date(document.dateSigned);
  const limitDate = new Date(currentDate.getFullYear(), 7, 1);

  if (signedDate < limitDate && currentDate >= limitDate) {
    hasDocumentsSignedBeforeLimitDate = true;
  }

  if (isNaN(new Date(document.dateSigned)) && currentDate >= limitDate) {
    hasDocumentsSignedBeforeLimitDate = true;
  }
}
ready

Revisions

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