Most of the code used in unity is written using a specific statement that can be used to detect the execution efficiency of the code c#,c#.
The detection code is as follows:
usingUnityengine;usingSystem.Collections; Public classTest:monobehaviour {voidUpdate () {if(Input.getkeydown (KEYCODE.G)) {testexetime (); } }voidTestexetime () {System.Diagnostics.Stopwatch Stopwatch =NewSystem.Diagnostics.Stopwatch (); Stopwatch. Start ();//Start monitoring code run timeTestFunc (); Stopwatch. Stop ();//Stop monitoring //Gets the total time measured by the current instanceSystem.TimeSpan TimeSpan = stopwatch. Elapsed;//Double hours = TimeSpan. TotalHours; Total Hours //double minutes = TimeSpan. Totalminutes; Total minutes //double seconds = TimeSpan. TotalSeconds; Total number of seconds Doublemilliseconds = TimeSpan. TotalMilliseconds;//Total number of milliseconds //Print code Execution timeDebug.Log (milliseconds); }voidTestFunc () {intm =124;intn = the;intMN = m + N; Debug.Log (MN); }}
operation, the following results can be obtained:
The Debug.Log (MN) in TestFunc () is commented out, and the test is
void TestFunc() { int124; int256; int mn = m + n; // Debug.Log(mn); }
Detect code execution time in Unity