Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
escaping html 32
(version: 1)
Comparing performance of:
escape with regex vs built in escaping
Created:
8 months ago
by:
Guest
Jump to the latest result
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>`)
built in escaping
for(let i = 300; i--;) escape2(`<p>&"'hello</p>`)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
escape with regex
built in escaping
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Comments
Confirm delete:
Do you really want to delete benchmark?