Skip to content

Commit ba6c7f5

Browse files
Release update
1 parent 2213742 commit ba6c7f5

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-adaptive-perf",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "Adaptive performance library for React — automatically adjusts animations and effects based on device capability",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",

src/detection.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,23 @@ export function benchmark(duration: number = 500): Promise<BenchmarkResult> {
360360
}
361361

362362
function 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

Comments
 (0)