loop function

Benchmark created on


Setup

const numericLowercaseComparator = { locale: null, collator: null };
const localeCompareNumericLowercase = (
  a,
  b,
  locale
) => {
  if (
    !numericLowercaseComparator.collator ||
    numericLowercaseComparator.locale !== locale
  ) {
    numericLowercaseComparator.locale = locale;
    numericLowercaseComparator.collator = new Intl.Collator(locale, {
      numeric: true,
      sensitivity: 'accent',
    });
  }
return numericLowercaseComparator.collator.compare(a, b)
}

const getNumericLowercaseComparator = (locale) => {
  if (
    !numericLowercaseComparator.collator ||
    numericLowercaseComparator.locale !== locale
  ) {
    numericLowercaseComparator.locale = locale;
    numericLowercaseComparator.collator = new Intl.Collator(locale, {
      numeric: true,
      sensitivity: 'accent',
    });
  }

  return numericLowercaseComparator.collator.compare;
}

data = ['x','y','z','z','y']

Test runner

Ready to run.

Testing in
TestOps/sec
localeCompareNumericLowercase
data.sort((a, b) => localeCompareNumericLowercase(a, b, "en"));



ready
getNumericLowercaseComparator
data.sort(getNumericLowercaseComparator("en"));
ready

Revisions

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