Created
March 23, 2026 15:58
-
-
Save hed0rah/4d1892df93fc611b3c4b656342bb3e02 to your computer and use it in GitHub Desktop.
JS Console Benchmark Tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // performance-test-snippets.js | |
| // Paste these one by one (or selected groups) into your custom JS console/TUI to stress-test performance monitoring | |
| // 1. Basic CPU burn (4 seconds of heavy math) | |
| let start = performance.now(); | |
| while (performance.now() - start < 4000) { | |
| Math.sqrt(Math.random() * Math.random() * 999999); | |
| } | |
| console.log("4-second CPU burn finished"); | |
| // 2. Very long synchronous loop – blocks main thread hard | |
| for (let i = 0; i < 800_000_000; i++) { | |
| // empty – pure CPU hog | |
| } | |
| console.log("Long sync loop done (probably took many seconds)"); | |
| // 3. Timer flooding (many short setTimeout calls) | |
| for (let i = 0; i < 4000; i++) { | |
| setTimeout(() => { | |
| if (i % 500 === 0) console.log(`Timer ${i} fired`); | |
| }, 1 + i % 16); | |
| } | |
| console.log("Scheduled 4000 short timers"); | |
| // 4. Heavy DOM thrashing (create + append many elements) | |
| const frag = document.createDocumentFragment(); | |
| for (let i = 0; i < 6000; i++) { | |
| const div = document.createElement("div"); | |
| div.textContent = "x".repeat(30 + (i % 100)); | |
| frag.appendChild(div); | |
| } | |
| document.body.appendChild(frag); | |
| console.log("Appended 6000 elements"); | |
| // 5. Memory leak simulation (growing array + closures + big strings) | |
| window.leak = window.leak || []; | |
| for (let i = 0; i < 15000; i++) { | |
| const big = new Array(5000).fill("x".repeat(80)); | |
| leak.push({ idx: i, data: big, fn: () => console.log(i) }); | |
| } | |
| console.log("Pushed 15k objects with 5k-string arrays each"); | |
| // 6. Rapid console spam (flood the console output) | |
| for (let i = 0; i < 12000; i++) { | |
| console.log(`[${i}] ` + "test ".repeat(8 + (i % 17)) + Math.random()); | |
| } | |
| // 7. Microtask storm via queueMicrotask | |
| Promise.resolve().then(() => { | |
| for (let i = 0; i < 10000; i++) { | |
| queueMicrotask(() => { | |
| if (i % 2000 === 0) console.log(`Microtask wave ${i}`); | |
| }); | |
| } | |
| }); | |
| console.log("Queued 10k microtasks"); | |
| // 8. Canvas stress (needs a <canvas> on page – creates one if missing) | |
| const canvas = document.querySelector("canvas") || document.createElement("canvas"); | |
| if (!canvas.parentNode) document.body.appendChild(canvas); | |
| const ctx = canvas.getContext("2d"); | |
| canvas.width = 1200; canvas.height = 800; | |
| for (let frame = 0; frame < 120; frame++) { | |
| ctx.fillStyle = `hsl(${frame * 3}, 80%, 50%)`; | |
| ctx.fillRect(Math.sin(frame) * 300 + 400, Math.cos(frame) * 200 + 300, 80, 80); | |
| for (let i = 0; i < 8000; i++) { | |
| ctx.globalAlpha = Math.random() * 0.4; | |
| ctx.fillRect(Math.random() * 1200, Math.random() * 800, 4, 4); | |
| } | |
| } | |
| console.log("Canvas stress loop done"); | |
| // 9. Heavy string concatenation (old-school GC/memory pressure) | |
| let huge = ""; | |
| for (let i = 0; i < 180000; i++) { | |
| huge += "more-text-" + i + " "; | |
| if (i % 30000 === 0) console.log(`String length now: ${huge.length.toLocaleString()}`); | |
| } | |
| console.log("Huge string concatenation finished"); | |
| // 10. Quick benchmark-style test with console.time | |
| console.time("fast-sort"); | |
| const arr = Array.from({ length: 400_000 }, () => Math.random() * 10000); | |
| arr.sort((a, b) => a - b); | |
| console.timeEnd("fast-sort"); | |
| // Bonus: Clear the leak array if you want to watch memory drop | |
| // window.leak = []; console.log("Leak array cleared"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment