country flags

Benchmark created on


Setup

const getFlagEmoji1 = (countryCode: string) => {
  const upCased = countryCode.toUpperCase();
  const codePoints = new Array<number>(upCased.length);
  for (let i = 0; i < upCased.length; i++) {
    codePoints[i] = 127397 + upCased.charCodeAt(i);
  }
  return String.fromCodePoint(...codePoints);
};

function getFlagEmoji2(countryCode) {
  return [...countryCode.toUpperCase()].map(char => 
      String.fromCodePoint(127397 + char.charCodeAt())
  ).reduce((a, b) => `${a}${b}`);
}

function getFlagEmoji3(countryCode) {
  const codePoints = countryCode
    .toUpperCase()
    .split('')
    .map(char =>  127397 + char.charCodeAt());
  return String.fromCodePoint(...codePoints);
}

Test runner

Ready to run.

Testing in
TestOps/sec
1
getFlagEmoji1('us');
ready
2
getFlagEmoji2('us');
ready

Revisions

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