JSDom vs document create element

Benchmark created on


Setup

const limit = 10_000

Test runner

Ready to run.

Testing in
TestOps/sec
JSDom
function decodeHtmlEntities(text) {
  if (!text) return "";

  try {
    // Use DOMParser to safely parse and decode HTML entities
    const parser = new DOMParser();
    const doc = parser.parseFromString(text, "text/html");
    return doc.documentElement.textContent || "";
  } catch {
    // Fallback: return original text if parsing fails
    return text;
  }
}
for (let i = 0; i < limit; i++) {
	decodeHtmlEntities("String")
}
ready
document create element
function decodeHtmlEntities(text) {
  if (!text) return "";

  const textarea = document.createElement("textarea");
  textarea.innerHTML = text;
  return textarea.value;
 }
for (let i = 0; i < limit; i++) {
	decodeHtmlEntities("String")
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.