replaceChildren vs documentFragment [2]
Date tested:
one year ago
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36
Test name
Executions per second
replaceChildren
1179048.0 Ops/sec
append documentFragment
746938.8 Ops/sec
Benchmark definition (click to collapse):
HTML Preparation code:
<div id="container"></div>
Script Preparation code:
var elements = [document.createElement('div'), document.createElement('div')]; var container = document.getElementById('container');
Tests:
replaceChildren
container.replaceChildren(...elements);
append documentFragment
var newChildren = document.createDocumentFragment(); newChildren.append(...elements); container.replaceChildren(newChildren);
Open this result on MeasureThat.net