3 ms·
Wait, not like this? document.documentElement.innerHTML = document.documentElement.innerHTML.replace( new RegExp('(?:' + ['pcwalton', 'patio11', 'j
by thesmallestcat 10y ago
Wait, not like this?
document.documentElement.innerHTML =
document.documentElement.innerHTML.replace(
new RegExp('(?:' + ['pcwalton', 'patio11', 'jblow', 'WalterBright'].join('|') + ')', 'g'),
'<B>$&</B>'
);
DHTML!
- chipperyman573 10y agoBecause regex is costly. Your solution takes 27.1 ms on my machine, and my script takes 12.4 ms.
- thesmallestcat 10y ago(It's a joke, with poor delivery it seems. It also pointlessly replaces things in <head>. Also, it clobbers every element on the page, attached event handlers included, so it's expensive and destructive. To be clear, it's expensive because it treats the page as a string rather than using the DOM and replaces every element, not because regular expressions are expensive, which they aren't. As far as string replacements go, it's pretty quick. The underlying joke is it's a 1997 JS novice/Perl monk's attempt at replacing your O(n*m) script, which really needs no optimization, hence the dated <B> and "DHTML!"... I'll see myself out).