As with any typical software development, once you have reached an optimization cycle, you will want to measure existing performance, make modifications to code, structures or data and then measure again and compare the results.
To keep this learning path a reasonable length, we will just measure and compare the final optimized versions against the original. We’ll collect data for plain, Burst and neon modes. This section will cover this using the Profiler and Analyzer tools in Unity.
For more detail regarding the Profiler and Analyzer, please read the previous learning path in this series, Profiling Unity apps on Android .
First, you will need a consistent scenario in which you can reliably compare the three modes. We need to compare the data when all the versions are processing the same amount of data. It’s important to note that the randomness of the scene can make it harder to pick representative frames but we can wait until the number of characters is the same in each run.
The sample generates new characters every frame up to a maximum of 2401. This maximum is reached in a couple of minutes or so.
Unfortunately, the sample code doesn’t display the character count but it can be added easily.
First, pass the character count to the ScreenWriteout
function call in Update. Line 265 becomes:
ScreenWriteout(numChar);
Now add the numChar
parameter to the function. Line 497 becomes:
private void ScreenWriteout(int numChar)
Now display the character count in the ScreenWriteout
function. Lines 506 and 507 become:
+ "Character Collisions: " + radiusCollideFrameTime().ToString("N3") + "ms\n"
+ "Characters: " + numChar.ToString();
You will need to ensure plain (unoptimized) mode is active:
Open Assets/BurstNeonCollisions/Scripts/CollisionCalculationScript.cs
Go to line 66
Edit the line to match the following:
public const Mode codeMode = Mode.Plain;
Open Build Settings from the File menu
Ensure the following options:
Development build is ticked
Autoconnect Profiler is ticked
Run Device is set to your Android device
Select Build and Run
Choose a filename, e.g., plain.apk
The application will build and deploy to your Android device
The Profiler will start collecting data automatically
Wait until the character count hits 2401 and then make sure to record for another 300 frames. If you prefer, you could clear the results as soon as the character count hits 2401, or not tick Autoconnect Profiler and start recording manually.
Select the disk icon in the top-right and save the data as plain.data
Repeat the above process to record performance data for Burst mode. All of the steps are the same except that we set the mode in CollisionCalculationScript.cs as follows:
public const Mode codeMode = Mode.Burst;
Name your apk burst.apk and your saved performance data as burst.data.
Repeat the above process again to record performance data for Neon mode. Again, the steps are the same except that we set the mode in CollisionCalculationScript.cs as follows:
public const Mode codeMode = Mode.Neon;
Name your apk neon.apk and your saved performance data as neon.data.