Measure and compare

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 .

Create a consistent scenario

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.

Display character count

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();
        
    

Record performance data for plain mode

You will need to ensure plain (unoptimized) mode is active:

  1. Open Assets/BurstNeonCollisions/Scripts/CollisionCalculationScript.cs

  2. Go to line 66

  3. Edit the line to match the following:

    

        
        
            public const Mode codeMode = Mode.Plain;
        
    
  1. Open Build Settings from the File menu

  2. Ensure the following options:

    1. Development build is ticked

    2. Autoconnect Profiler is ticked

    3. Run Device is set to your Android device

  3. Select Build and Run

  4. Choose a filename, e.g., plain.apk

  5. The application will build and deploy to your Android device

  6. The Profiler will start collecting data automatically

  7. 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.

  8. Select the disk icon in the top-right and save the data as plain.data

Record performance data for Burst mode

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.

Record performance data for Neon mode

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.

Back
Next