Loop Performance (v3)

Revision 3 of this 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"
  },
  {
    amount: "350",
    expectedTime: "150 minutes",
    dateSigned: "2024-03-10T09:30:00.000Z"
  },
  {
    amount: "400",
    expectedTime: "180 minutes",
    dateSigned: "2024-04-25T11:45:00.000Z"
  },
  {
    amount: "450",
    expectedTime: "210 minutes",
    dateSigned: "2024-05-15T14:20:00.000Z"
  },
  {
    amount: "500",
    expectedTime: "240 minutes",
    dateSigned: "2024-06-05T16:55:00.000Z"
  },
  {
    amount: "550",
    expectedTime: "270 minutes",
    dateSigned: "2024-07-20T18:30: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
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
for with breakers
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
    break
  }

  if (isNaN(new Date(document.dateSigned)) && currentDate >= limitDate) {
    hasDocumentsSignedBeforeLimitDate = true
    break
  }
}
ready
for w/ breakers (improved)
const limitDate = new Date(currentDate.getFullYear(), 7, 1);
  
for (const document of documents) {
  const signedDate = new Date(document.dateSigned);
  
  if (signedDate < limitDate && currentDate >= limitDate) {
    hasDocumentsSignedBeforeLimitDate = true
    break
  }

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

Revisions

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