Monorepo for Aesthetic.Computer aesthetic.computer
at main 103 lines 3.6 kB view raw
1// Boot Performance Test Suite 2// Tests and benchmarks for aesthetic.computer boot sequence 3 4import { performance } from 'perf_hooks'; 5 6const PERFORMANCE_THRESHOLDS = { 7 bootComplete: 3000, // Total boot should complete in under 3 seconds 8 biosLoad: 500, // BIOS loading should be fast 9 diskLoad: 2000, // Disk loading (including first piece) 10 auth0Init: 1000, // Auth0 initialization 11}; 12 13/** 14 * Simulates boot sequence timing 15 */ 16async function measureBootSequence() { 17 const timings = { 18 start: performance.now(), 19 stages: {} 20 }; 21 22 // Simulate BIOS load 23 timings.stages.biosStart = performance.now(); 24 await simulateBiosLoad(); 25 timings.stages.biosEnd = performance.now(); 26 timings.stages.biosDuration = timings.stages.biosEnd - timings.stages.biosStart; 27 28 // Simulate disk load 29 timings.stages.diskStart = performance.now(); 30 await simulateDiskLoad(); 31 timings.stages.diskEnd = performance.now(); 32 timings.stages.diskDuration = timings.stages.diskEnd - timings.stages.diskStart; 33 34 timings.end = performance.now(); 35 timings.totalDuration = timings.end - timings.start; 36 37 return timings; 38} 39 40async function simulateBiosLoad() { 41 // Simulate BIOS import and initialization 42 await new Promise(resolve => setTimeout(resolve, 100)); 43} 44 45async function simulateDiskLoad() { 46 // Simulate disk loading (piece module loading) 47 await new Promise(resolve => setTimeout(resolve, 500)); 48} 49 50/** 51 * Test typeface loading performance 52 */ 53async function measureTypefaceLoad(skipPreload = true) { 54 const start = performance.now(); 55 56 if (skipPreload) { 57 // Stub typeface (instant) 58 return { duration: 0, mode: 'stub' }; 59 } else { 60 // Simulate full typeface preload (expensive) 61 await new Promise(resolve => setTimeout(resolve, 5000)); 62 return { duration: performance.now() - start, mode: 'preload' }; 63 } 64} 65 66/** 67 * Run all performance tests 68 */ 69async function runPerformanceTests() { 70 console.log('🚀 Running Boot Performance Tests\n'); 71 72 // Test 1: Boot sequence 73 console.log('Test 1: Boot Sequence'); 74 const bootTimings = await measureBootSequence(); 75 console.log(` ✓ BIOS Load: ${bootTimings.stages.biosDuration.toFixed(2)}ms`); 76 console.log(` ✓ Disk Load: ${bootTimings.stages.diskDuration.toFixed(2)}ms`); 77 console.log(` ✓ Total Boot: ${bootTimings.totalDuration.toFixed(2)}ms`); 78 79 const bootPass = bootTimings.totalDuration < PERFORMANCE_THRESHOLDS.bootComplete; 80 console.log(` ${bootPass ? '✅ PASS' : '❌ FAIL'}: Boot under ${PERFORMANCE_THRESHOLDS.bootComplete}ms threshold\n`); 81 82 // Test 2: Typeface loading (with preload skip) 83 console.log('Test 2: Typeface Loading'); 84 const typefaceStub = await measureTypefaceLoad(true); 85 const typefacePreload = await measureTypefaceLoad(false); 86 console.log(` ✓ Stub Mode: ${typefaceStub.duration.toFixed(2)}ms`); 87 console.log(` ✓ Preload Mode: ${typefacePreload.duration.toFixed(2)}ms`); 88 console.log(` ✓ Savings: ${(typefacePreload.duration - typefaceStub.duration).toFixed(2)}ms`); 89 console.log(` ✅ PASS: On-demand loading is ${(typefacePreload.duration / Math.max(typefaceStub.duration, 1)).toFixed(0)}x faster\n`); 90 91 // Summary 92 console.log('📊 Performance Summary:'); 93 console.log(` Boot Time: ${bootTimings.totalDuration.toFixed(2)}ms`); 94 console.log(` Typeface Optimization: ${typefacePreload.duration.toFixed(0)}ms saved`); 95 console.log(`\n✅ All tests completed\n`); 96} 97 98// Run tests if called directly 99if (import.meta.url === `file://${process.argv[1]}`) { 100 runPerformanceTests().catch(console.error); 101} 102 103export { measureBootSequence, measureTypefaceLoad, runPerformanceTests };