@@ -97,21 +97,28 @@ function resetParseServer() {
9797 * Measure average time for an async operation over multiple iterations
9898 * Uses warmup iterations, median metric, and outlier filtering for robustness
9999 */
100- async function measureOperation ( name , operation , iterations = ITERATIONS ) {
101- const warmupCount = Math . floor ( iterations * 0.2 ) ; // 20% warmup iterations
100+ async function measureOperation ( name , operation , iterations = ITERATIONS , skipWarmup = false ) {
101+ const warmupCount = skipWarmup ? 0 : Math . floor ( iterations * 0.2 ) ; // 20% warmup iterations
102102 const times = [ ] ;
103103
104- // Warmup phase - stabilize JIT compilation and caches
105- for ( let i = 0 ; i < warmupCount ; i ++ ) {
106- await operation ( ) ;
104+ if ( warmupCount > 0 ) {
105+ console . log ( `Starting warmup phase (${ warmupCount } iterations)...` ) ;
106+ const warmupStart = performance . now ( ) ;
107+ for ( let i = 0 ; i < warmupCount ; i ++ ) {
108+ await operation ( ) ;
109+ }
110+ console . log ( `Warmup took: ${ ( performance . now ( ) - warmupStart ) . toFixed ( 2 ) } ms` ) ;
107111 }
108112
109113 // Measurement phase
114+ console . log ( `Starting measurement phase (${ iterations } iterations)...` ) ;
110115 for ( let i = 0 ; i < iterations ; i ++ ) {
111116 const start = performance . now ( ) ;
112117 await operation ( ) ;
113118 const end = performance . now ( ) ;
114- times . push ( end - start ) ;
119+ const duration = end - start ;
120+ times . push ( duration ) ;
121+ console . log ( `Iteration ${ i + 1 } : ${ duration . toFixed ( 2 ) } ms` ) ;
115122 }
116123
117124 // Sort times for percentile calculations
@@ -409,6 +416,8 @@ async function runBenchmarks() {
409416 if ( server ) {
410417 server . close ( ) ;
411418 }
419+ // Give some time for cleanup
420+ setTimeout ( ( ) => process . exit ( 0 ) , 1000 ) ;
412421 }
413422}
414423
0 commit comments