Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
"decodeHTMLEntities" vs DOM Parser
This benchmark compares the "decodeHTMLEntities" function proposed by https://stackoverflow.com/questions/5796718/html-entity-decode and the solution via DOMParser.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser:
Chrome 133
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
CreateElement_div
142890528.0 Ops/sec
DOMParser
157377296.0 Ops/sec
Script Preparation code:
var testString = '<body><script>alert(1);</script foo="bar">' + Array(100001).join('<div>x</div>') + '</body>';
Tests:
CreateElement_div
function test_innerHTML() { var element = document.createElement('div'); function decodeHTMLEntities(str) { if (str && typeof str === 'string') { // strip script/html tags str = str.replace(/<script[^>]*>([\S\s]*?)<\/script>/gmi, ''); str = str.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gmi, ''); element.innerHTML = str; str = element.textContent; element.textContent = ''; } return str; } return decodeHTMLEntities(testString); }
DOMParser
function test_DOMParser() { return (new DOMParser).parseFromString(testString, 'text/html').documentElement.innerText; }