JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<section id="container"></section>
<label>Slow:</label>: <span id="slow"></span>
<br />
<label>Fast:</label>: <span id="fast"></span>
</body>
JavaScript
var n = 100;
var contents;
function reset() {
container.innerHTML = '';
contents = [];
for (var i = 0; i < n; i++) {
var div = document.createElement('div');
container.appendChild(div);
}
}
function clearContents(fast) {
reset();
els = document.getElementsByTagName("div");
start = performance.now();
if (fast) clearFast(els);
else clearSlow(els);
return (performance.now() - start)
}
function clearSlow(divs) {
Array.prototype.forEach.call(divs, function (div) {
contents.push(div.clientWidth);
div.style.width = "10px";
});
}
function clearFast(divs) {
Array.prototype.forEach.call(divs, function (div) {
contents.push(div.clientWidth);
});
Array.prototype.forEach.call(divs, function (div) {
div.style.width = "10px";
});
}
document.getElementById("slow").innerHTML = clearContents(false);
document.getElementById("fast").innerHTML = clearContents(true);