Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
escaping html 3232
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Browser:
Chrome 139
Operating system:
Linux
Device Platform:
Desktop
Date tested:
8 months ago
Test name
Executions per second
escape with regex
29.9 Ops/sec
built in escaping
90.7 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
function esc(a, b, i) { let { 0: regex, 1: rep } = specialChars[i] return`${a.replace(regex, rep)}${typeof b === 'string' ? b.replace(regex, rep) : ''}` } function escape1(str) { return specialChars.reduce(esc, str) } const specialChars = [[/>/g, '>'], [/</g, '<'], [/&(?![#\w]+;)/g, '&'], [/'/g, '''], [/"/g, '"']] let n = document.createElement('div') function escape2(str) { n.textContent = str return n.innerHTML }
Tests:
escape with regex
for(let i = 300; i--;) escape1(`<p>&"'hello</p>`.repeat(600))
built in escaping
for(let i = 300; i--;) escape2(`<p>&"'hello</p>`.repeat(600))