initial commit

This commit is contained in:
Brooke Vibber 2023-09-14 12:53:30 -07:00
commit 04e0dd6a44

64
index.html Normal file
View file

@ -0,0 +1,64 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Massive memory allocation test</title>
</head>
<h1>
<h1>Massive memory allocation test</h1>
<p>
Allocates 16-MiB ArrayBuffers until something stops it.
May crash your system or make it sluggish.
</p>
<div id="status">Ready to start.</div>
<div><button id="start">Start</button></div>
<script async>
function el(id) {
return document.getElementById(id);
}
const status = el('status');
const button = el('start');
let running = false;
let count = 0;
// Give us 16 megs of randomized memory
// to defeat compression.
const mib = 1024 * 1024;
const chunk = 16 * mib;
const block = new Uint8Array(chunk);
for (let i = 0; i < block.length; i++) {
block[i] = Math.round(Math.random() * 255);
}
let blocks = [];
function alloc() {
blocks.push(block.slice());
count++;
status.textContent = `${count * chunk / mib} MiB allocated`;
}
let timeout = null;
function schedule() {
timeout = setTimeout(() => {
alloc();
schedule();
});
}
function cancel() {
clearTimeout(timeout);
timeout = null;
}
button.addEventListener('click', function(event) {
if (running) {
button.textContent = 'Start';
running = false;
cancel();
} else {
button.textContent = 'Stop';
running = true;
schedule();
}
});
</script>
</body>
</html>