lodash isEqual performance

Benchmark created on


Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.5.0/lodash.min.js"></script>

Setup

const ADAGE_FILTERS_DEFAULT_VALUES = {
  domains: [],
  students: [],
  departments: [],
  academies: [],
  eventAddressType: "other",
  geolocRadius: 50,
  formats: [],
  venue: null,
}

const getRandomInt = (min, max) => {
  return Math.floor(Math.random() * (max - min + 1)) + min;
};

const getRandomString = (length) => {
  const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  let result = '';
  for (let i = 0; i < length; i++) {
    result += characters.charAt(Math.floor(Math.random() * characters.length));
  }
  return result;
};

const generateFakeVenue = () => {
  return {
    adageId: Math.random() > 0.5 ? getRandomString(8) : null,
    departementCode: getRandomString(2),
    id: getRandomInt(1, 1000),
    name: getRandomString(10),
    publicName: Math.random() > 0.5 ? getRandomString(12) : null,
    relative: Array.from({ length: getRandomInt(1, 5) }, () => getRandomInt(1, 1000)),
  };
};

const generateFakeFilters = (nbToGenerate) => {
  return Array.from({ length: nbToGenerate }, () => ({
    domains: Array.from({ length: getRandomInt(1, 5) }, () => getRandomInt(1, 100)),
    students: Array.from({ length: getRandomInt(1, 5) }, () => getRandomString(6)),
    departments: Array.from({ length: getRandomInt(1, 5) }, () => getRandomString(2)),
    academies: Array.from({ length: getRandomInt(1, 5) }, () => getRandomString(3)),
    eventAddressType: getRandomString(5),
    geolocRadius: getRandomInt(10, 100),
    formats: Array.from({ length: getRandomInt(1, 3) }, () => getRandomString(4)),
    venue: Math.random() > 0.5 ? generateFakeVenue() : null,
  }));
};

const areFiltersEmpty = (filters) => {
  return (
    filters.domains.length === ADAGE_FILTERS_DEFAULT_VALUES.domains.length &&
    filters.departments.length ===
      ADAGE_FILTERS_DEFAULT_VALUES.departments.length &&
    filters.academies.length ===
      ADAGE_FILTERS_DEFAULT_VALUES.academies.length &&
    filters.eventAddressType ===
      ADAGE_FILTERS_DEFAULT_VALUES.eventAddressType &&
    filters.geolocRadius === ADAGE_FILTERS_DEFAULT_VALUES.geolocRadius &&
    filters.formats.length === ADAGE_FILTERS_DEFAULT_VALUES.formats.length &&
    filters.venue === ADAGE_FILTERS_DEFAULT_VALUES.venue &&
    filters.students.length === ADAGE_FILTERS_DEFAULT_VALUES.students.length
  )
}

const filters = generateFakeFilters(5000);

Test runner

Ready to run.

Testing in
TestOps/sec
comparison with "lodash.isEqual"
for (const f of filters) {
  _.isEqual(f, ADAGE_FILTERS_DEFAULT_VALUES)
}
ready
comparison with "areFiltersEmpty" (manual function)
for (const f of filters) {
  areFiltersEmpty(f)
}
ready

Revisions

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