Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add C# example to CPU optimization #9810

Merged
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