Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save vsemozhetbyt/353a8e0bcd8eae912b06fafa2960bb83 to your computer and use it in GitHub Desktop.

Select an option

Save vsemozhetbyt/353a8e0bcd8eae912b06fafa2960bb83 to your computer and use it in GitHub Desktop.
str.split vs spread: unicodewise
'use strict';
const str = '\ud83d\udc0e'.repeat(1e4); // 🐎
const re = new RegExp('', 'u'); // or /[^]{0}/u
let symbols;
let i;
console.time('RegExp');
for (i = 0; i < 1e4; i++) symbols = str.split(re);
console.timeEnd('RegExp');
console.time('Spread');
for (i = 0; i < 1e4; i++) symbols = [...str];
console.timeEnd('Spread');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment