<!doctype html>
<html>
<head>
<link rel="stylesheet" href="lib/style.css">
<script src="lib/script.js"></script>
</head>
<body>
<script src="/lib/script.js"></script>
<button onclick="measureMemory()">Measure Memory</button>
</body>
</html>
function logMemory() {
if (typeof process != 'undefined') {
console.log(`Node: ${process.memoryUsage().heapUsed / Math.pow(1000, 2)} MB`);
} else if (performance) {
console.log(`Browser: ${performance.memory.usedJSHeapSize / Math.pow(1000, 2)} MB`);
} else {
throw ('Where d-heck are you trying to run me?');
}
}
function measureMemory() {
const arraySize = 25 * Math.pow(1000, 2);
logMemory();
(function() {
const array1 = new Array(arraySize).fill(1.1);
logMemory();
})();
(function() {
const array2 = new Array(arraySize).fill(1);
logMemory()
})();
setTimeout(() => {
logMemory();
}, 5000);
}
measureMemory();