소스 검색

Add C# examples to CPU optimization

Co-authored-by: A Thousand Ships <[email protected]>
Shawn Hardern 1 년 전
부모
커밋
0edbe34b89
1개의 변경된 파일12개의 추가작업 그리고 1개의 파일을 삭제
  1. 12 1
      tutorials/performance/cpu_optimization.rst

+ 12 - 1
tutorials/performance/cpu_optimization.rst

@@ -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 specifics vary depending on the language, but in GDScript, you would do
 the following:
 the following:
 
 
-::
+.. tabs::
+ .. code-tab:: gdscript GDScript
 
 
     var time_start = Time.get_ticks_usec()
     var time_start = Time.get_ticks_usec()
 
 
@@ -102,6 +103,16 @@ the following:
     var time_end = Time.get_ticks_usec()
     var time_end = Time.get_ticks_usec()
     print("update_enemies() took %d microseconds" % time_end - time_start)
     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
 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
 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.
 function). The reason for doing this is that timers often have limited accuracy.