asdf
Squash the current repository state back into one baseline commit while preserving the README reframing and repository contents. Constraint: User explicitly requested a single squashed commit with subject "asdf" Confidence: high Scope-risk: broad Reversibility: clean Directive: This commit intentionally rewrites published history; coordinate before future force-pushes Tested: git status clean; local history rewritten to one commit; force-pushed main to origin and instructkr Not-tested: Fresh clone verification after push
This commit is contained in:
commit
d2542c9a62
47
src/utils/fpsTracker.ts
Normal file
47
src/utils/fpsTracker.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
export type FpsMetrics = {
|
||||
averageFps: number
|
||||
low1PctFps: number
|
||||
}
|
||||
|
||||
export class FpsTracker {
|
||||
private frameDurations: number[] = []
|
||||
private firstRenderTime: number | undefined
|
||||
private lastRenderTime: number | undefined
|
||||
|
||||
record(durationMs: number): void {
|
||||
const now = performance.now()
|
||||
if (this.firstRenderTime === undefined) {
|
||||
this.firstRenderTime = now
|
||||
}
|
||||
this.lastRenderTime = now
|
||||
this.frameDurations.push(durationMs)
|
||||
}
|
||||
|
||||
getMetrics(): FpsMetrics | undefined {
|
||||
if (
|
||||
this.frameDurations.length === 0 ||
|
||||
this.firstRenderTime === undefined ||
|
||||
this.lastRenderTime === undefined
|
||||
) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const totalTimeMs = this.lastRenderTime - this.firstRenderTime
|
||||
if (totalTimeMs <= 0) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const totalFrames = this.frameDurations.length
|
||||
const averageFps = totalFrames / (totalTimeMs / 1000)
|
||||
|
||||
const sorted = this.frameDurations.slice().sort((a, b) => b - a)
|
||||
const p99Index = Math.max(0, Math.ceil(sorted.length * 0.01) - 1)
|
||||
const p99FrameTimeMs = sorted[p99Index]!
|
||||
const low1PctFps = p99FrameTimeMs > 0 ? 1000 / p99FrameTimeMs : 0
|
||||
|
||||
return {
|
||||
averageFps: Math.round(averageFps * 100) / 100,
|
||||
low1PctFps: Math.round(low1PctFps * 100) / 100,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user