Skip to content

Instantly share code, notes, and snippets.

@GiwbyAlbatross
Last active March 12, 2026 01:15
Show Gist options
  • Select an option

  • Save GiwbyAlbatross/716ac1076c6f0e3725fcce5920117a73 to your computer and use it in GitHub Desktop.

Select an option

Save GiwbyAlbatross/716ac1076c6f0e3725fcce5920117a73 to your computer and use it in GitHub Desktop.
Get CPU and GPU time in GDScript.
# effectively stolen from https://github.com/godot-extended-libraries/godot-debug-menu credit to Calinou :D
# frametime_* is in milliseconds
# fps_* is in frames per second (what else)
var viewport_rid = get_viewport().get_viewport_rid()
var frametime_cpu: int = RenderingServer.viewport_get_measured_render_time_cpu(viewport_rid) + RenderingServer.get_frame_setup_time_cpu()
var frametime_gpu: int = RenderingServer.viewport_get_measured_render_time_gpu(viewport_rid)
var fps_real: float = 1 / delta # assuming this is in _process, returns actual frame rate, capped at display refresh rate
var fps_theo: float = 1000 / max(frametime_cpu, frametime_gpu) # frame rate that could be attained if there was no FPS cap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment