Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion tutorials/performance/cpu_optimization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ using a profiler, is to manually time the function or area under test.
The specifics vary depending on the language, but in GDScript, you would do
the following:

::
.. tabs::
.. code-tab:: gdscript GDScript

var time_start = Time.get_ticks_usec()

Expand All @@ -102,6 +103,16 @@ the following:
var time_end = Time.get_ticks_usec()
print("update_enemies() took %d microseconds" % time_end - time_start)

.. code-tab:: csharp

var timeStart = Time.GetTicksUsec();

// Your function you want to time.
UpdateEnemies();

var timeEnd = Time.GetTicksUsec();
GD.Print($"UpdateEnemies() took {timeEnd - timeStart} microseconds");

When manually timing functions, it is usually a good idea to run the function
many times (1,000 or more times), instead of just once (unless it is a very slow
function). The reason for doing this is that timers often have limited accuracy.
Expand Down