JSFiddle - React, Tailwind, and code Playground
HTML
<div id="stats"></div>
<div style="display: none" id="debug"></div>
JavaScript
(function () {
var x = [];
function createSomeNodes() {
var div,
i = 100,
frag = document.createDocumentFragment();
for (; i > 0; i--) {
div = document.createElement("div");
div.appendChild(document.createTextNode(
i + " - " + new Date().toTimeString()));
frag.appendChild(div);
}
document.getElementById("debug").appendChild(frag);
}
function clear() {
document.getElementById('stats').innerHTML = '';
}
function show(stat) {
var div = document.getElementById('stats');
div.appendChild(document.createTextNode(stat));
div.appendChild(document.createElement("div"));
}
var start = Date.now() + 2 * 1000;
function grow() {
x.push(new Array(1000000).join('x'));
createSomeNodes();
setTimeout(grow, 100);
if (Date.now() < start) {
return;
}
(function () {
clear();
var pm = window.performance && window.performance.memory;
if (!pm) {
show("no performance.memory api");
return;
}
// Memory the JavaScript heap is limited to
var lim = pm.jsHeapSizeLimit,
// Memory allocated on the JavaScript heap
total = pm.totalJSHeapSize,
used = pm.usedJSHeapSize; // Memory currently being used
show("Crash Index (% of Heap Limit Allocated): " + Math.round(total / lim * 100));
show("% of Allocated Memory Used: " + Math.round(used / total * 100));
})();
}
setTimeout(grow, 1000);
})()