Skip to content

Instantly share code, notes, and snippets.

@daisyUniverse
Created April 9, 2025 18:15
Show Gist options
  • Save daisyUniverse/13f113039ecadfa8061de0205a2fb978 to your computer and use it in GitHub Desktop.
Save daisyUniverse/13f113039ecadfa8061de0205a2fb978 to your computer and use it in GitHub Desktop.
Powershell FPS Counter class
class FPSCounter {
[int]$FrameCount = 0
[System.Diagnostics.Stopwatch]$Stopwatch
[double]$LastTime = 0
[double]$FPS = 0
FPSCounter() {
$this.Stopwatch = [System.Diagnostics.Stopwatch]::new()
$this.Stopwatch.Start()
$this.LastTime = 0
}
[double] Update() {
$this.FrameCount++
$currentTime = $this.Stopwatch.Elapsed.TotalSeconds
$elapsed = $currentTime - $this.LastTime
if ($elapsed -ge 1.0) {
$this.FPS = [Math]::Round($this.FrameCount / $elapsed, 2)
$this.FrameCount = 0
$this.LastTime = $currentTime
}
return $this.FPS
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment