Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
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:
4 months ago
Benchmark engine:
Benchmark.js
DOMParser
697.8M/s
.createHTMLDocument() + .innerHTML
680.7M/s
Nested .createElement() + .appendChild()
680.5M/s
.createElement() + .innerHTML
621.5M/s
View exact numbers
Test name
Executions per second
✓
DOMParser
697,842,112 Ops/sec
.createHTMLDocument() + .innerHTML
680,725,440 Ops/sec
Nested .createElement() + .appendChild()
680,452,736 Ops/sec
.createElement() + .innerHTML
621,495,360 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; }