Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Chrome 125
Windows
Desktop
7 months ago
Test name Executions per second
createElement 1320.8 Ops/sec
createDocumentFragment 1462.4 Ops/sec
Script Preparation code:
AخA
 
document.body.innerHTML = "";
Tests:
  • createElement

     
    var root = document.createElement("div");
    document.body.appendChild(root);
    for (var i = 0; i < 1000; i++) {
        var e = document.createElement("span");
        e.innerText = i + " text";
        root.appendChild(e);
    }
  • createDocumentFragment

     
    var frag = document.createDocumentFragment();
    var root = document.createElement("div");
    for (var i = 0; i < 1000; i++) {
        var e = document.createElement("span");
        e.innerText = i + " text";
        root.appendChild(e);
    }
    document.body.appendChild(frag);