@@ -360,13 +360,23 @@ export function benchmark(duration: number = 500): Promise<BenchmarkResult> {
360360}
361361
362362function calculateResult ( frameTimes : number [ ] ) : BenchmarkResult {
363- const total = frameTimes . length ;
364- const duration = frameTimes . reduce ( ( a , b ) => a + b , 0 ) ;
363+ // Skip the first frame as it often includes setup time and is unreliable
364+ // Also filter out extreme outliers (> 100ms) that indicate tab switching or throttling
365+ const validTimes = frameTimes . slice ( 1 ) . filter ( t => t > 0 && t < 100 ) ;
366+
367+ if ( validTimes . length === 0 ) {
368+ return { fps : 60 , frameDrops : 0 , jank : 0 , avgFrameTime : 16.67 } ;
369+ }
370+
371+ const total = validTimes . length ;
372+ const duration = validTimes . reduce ( ( a , b ) => a + b , 0 ) ;
373+ const avgFrameTime = duration / total ;
374+
365375 return {
366- fps : Math . round ( ( total / duration ) * 1000 * 10 ) / 10 ,
367- frameDrops : frameTimes . filter ( t => t > 33.33 ) . length ,
368- jank : frameTimes . filter ( t => t > 16.67 ) . length ,
369- avgFrameTime : Math . round ( ( duration / total ) * 100 ) / 100 ,
376+ fps : Math . round ( ( 1000 / avgFrameTime ) * 10 ) / 10 ,
377+ frameDrops : validTimes . filter ( t => t > 33.33 ) . length ,
378+ jank : validTimes . filter ( t => t > 16.67 ) . length ,
379+ avgFrameTime : Math . round ( avgFrameTime * 100 ) / 100 ,
370380 } ;
371381}
372382
0 commit comments