Skip to content

Commit

Permalink
Merge pull request #9810 from ShawnHardern/update-CPU-optimization-cs…
Browse files Browse the repository at this point in the history
…harp

Add C# example to CPU optimization
  • Loading branch information
AThousandShips authored Aug 23, 2024
2 parents 69fe8f0 + 0edbe34 commit b685a63
Showing 1 changed file with 12 additions and 1 deletion.
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

0 comments on commit b685a63

Please sign in to comment.