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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36 Edg/148.0.0.0
Browser:
Chrome 148
Operating system:
Windows
Device Platform:
Desktop
Date tested:
3 months ago
Benchmark engine:
Benchmark.js
Nested .createElement() + .appendChild()
26.6M/s
.createHTMLDocument() + .innerHTML
26.0M/s
.createElement() + .innerHTML
25.9M/s
DOMParser
25.7M/s
View exact numbers
Test name
Executions per second
✓
Nested .createElement() + .appendChild()
26,638,654 Ops/sec
.createHTMLDocument() + .innerHTML
25,968,126 Ops/sec
.createElement() + .innerHTML
25,887,926 Ops/sec
DOMParser
25,742,468 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; }