how to measure execution speed in gd code?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By eaglecat
:warning: Old Version Published before Godot 3 was released.

Hi.
I got frame drop problem in my project.
so I want to know which line makes lag.
how can I measure execution speed in gd code?

:bust_in_silhouette: Reply From: Zylann

You can try this old method:

var time_before = OS.get_ticks_msec()

# Do stuff

var total_time = OS.get_ticks_msec() - time_before
print("Time taken: " + str(total_time))

you can see the delay of _process and _fixed_process in the debugger at runtime as well, but this method is better for specific segments of the code

batmanasb | 2016-04-02 23:35

nice. simple. thank you

eaglecat | 2016-04-03 03:29

:bust_in_silhouette: Reply From: salihkallai

Godot 4 solution:

var time_before = Time.get_ticks_msec()

# Do stuff

var total_time = Time.get_ticks_msec() - time_before
print("Time taken: " + str(total_time))