Something went wrong. Try again.
javascript for 🐜's, a tiny runtime with big ambitions antjs.org
Something went wrong. Try again.
JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657// Timer GC stress: interval-driven allocation without coroutines
function stripAnsi(str) { return str.replace(/\x1b\[[0-9;]*m/g, '');}
function pad(str, len) { const visible = stripAnsi(str).length; const diff = len - visible; if (diff <= 0) return str; return str + ' '.repeat(diff);}
function render() { const width = 120; const height = 40; const lines = [];
for (let y = 0; y < height; y++) { lines.push(' '.repeat(width)); }
for (let y = 0; y < height; y++) { let text = `\x1b[38;5;196mRow ${y}\x1b[0m: `; text += `\x1b[38;5;82m${'█'.repeat(20)}\x1b[0m`; text += `\x1b[2m${'░'.repeat(20)}\x1b[0m`; text = pad(text, width); lines[y] = text; }
return lines.join('\n');}
function handleEvent(n) { for (let i = 0; i < 10; i++) { render(); }}
let count = 0;const interval = setInterval(() => { count++; handleEvent(count);
const s = Ant.stats(), a = s.alloc, M = 1024 * 1024; const total = (s.pools.totalUsed + a.total) / M; console.log( `tick ${count}: pools ${(s.pools.totalUsed/M).toFixed(1)}MB obj ${(a.objects/M).toFixed(1)}MB shp ${(a.shapes/M).toFixed(1)}MB arr ${(a.arrays/M).toFixed(1)}MB refs ${(a.propRefs/M).toFixed(1)}MB cls ${(a.closures/M).toFixed(1)}MB uv ${(a.upvalues/M).toFixed(1)}MB ov ${(a.overflow/M).toFixed(1)}MB | ${total.toFixed(1)}MB rss ${(s.rss/M).toFixed(1)}MB` );
if (count >= 500) { clearInterval(interval); const a = Ant.stats(); console.log(`done: total ${((a.pools.totalUsed + a.alloc.total) / 1024 / 1024).toFixed(1)}MB`); }}, 10);