Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
.createElement() vs .createHTMLDocument() vs DOMParser() vs .appendChild()
Test performance between using document.createElement(), document.createHTMLDocument(), DOMParser(), and building up a DOM tree with .appendChild()
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:149.0) Gecko/20100101 Firefox/149.0
Browser:
Firefox 149
Operating system:
Linux
Device Platform:
Desktop
Date tested:
7 days ago
Test name
Executions per second
.createElement() + .innerHTML
621495360.0 Ops/sec
.createHTMLDocument() + .innerHTML
680725440.0 Ops/sec
DOMParser
697842112.0 Ops/sec
Nested .createElement() + .appendChild()
680452736.0 Ops/sec
Script Preparation code:
const count = 20_000; const testString = '<div>' + (new Array(count)).fill('').join('<b>x</b>') + '</div>';
Tests:
.createElement() + .innerHTML
function test_innerHTML() { const body = document.createElement('body'); body.innerHTML = testString; return body; }
.createHTMLDocument() + .innerHTML
function test_createHTMLDocument() { const doc = document.implementation.createHTMLDocument(''); doc.body.innerHTML = testString; return doc.body; }
DOMParser
function test_DOMParser() { return (new DOMParser()).parseFromString(testString, 'text/html').body; }
Nested .createElement() + .appendChild()
function test_innerHTML() { let i = -1; const div = document.createElement('div'); while (++i < count) { const b = document.createElement('b'); b.textContent = 'x'; div.appendChild(b); } return div; }