0
0
Unityframework~20 mins

Performance profiling in Unity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Unity Performance Profiler Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Understanding Unity Profiler Output
What will be the main visible effect in the Unity Profiler when the following code runs inside Update() method of a MonoBehaviour?
Unity
void Update() {
    for (int i = 0; i < 100000; i++) {
        float x = Mathf.Sqrt(i);
    }
}
AHigh GPU usage shown under 'Rendering' section with increased draw calls
BHigh CPU usage shown under 'Scripts' section with increased time in 'Update' method
CMemory spike shown under 'Memory' section due to many allocations
DNo significant change in profiler because Mathf.Sqrt is optimized
Attempts:
2 left
💡 Hint
Think about what part of the game loop the code runs in and what kind of resource it uses.
🧠 Conceptual
intermediate
1:30remaining
Purpose of Unity Profiler Markers
What is the main purpose of adding custom profiler markers in Unity code using Profiler.BeginSample and Profiler.EndSample?
ATo measure and visualize the time spent in specific code blocks during profiling
BTo reduce memory usage by marking unused code
CTo automatically optimize the marked code sections at runtime
DTo enable multi-threading for the marked code sections
Attempts:
2 left
💡 Hint
Think about what profiling means and what you want to learn from it.
🔧 Debug
advanced
2:00remaining
Identifying Cause of Garbage Collection Spikes
You notice frequent spikes in the Unity Profiler's GC Alloc column during gameplay. Which code snippet below is most likely causing these spikes?
Aint total = playerScore + enemyScore;
BVector3 pos = transform.position;
Cstring s = "Score: " + playerScore.ToString();
Dfloat speed = 5.0f * Time.deltaTime;
Attempts:
2 left
💡 Hint
Think about which operations create new objects in memory.
📝 Syntax
advanced
1:30remaining
Correct Use of Profiler API in Unity
Which of the following code snippets correctly uses Unity's Profiler API to measure a code block's performance?
A
Profiler.Begin("MyCode");
// code to measure
Profiler.End();
B
Profiler.StartSample("MyCode");
// code to measure
Profiler.StopSample();
C
Profiler.MarkSample("MyCode");
// code to measure
Profiler.EndSample();
D
Profiler.BeginSample("MyCode");
// code to measure
Profiler.EndSample();
Attempts:
2 left
💡 Hint
Check the exact method names in Unity's Profiler class.
🚀 Application
expert
3:00remaining
Optimizing a Frame Rate Drop Using Profiler Data
You profile your Unity game and see a large spike in the 'Rendering' section caused by many dynamic shadows. Which approach will most effectively reduce this spike?
AReduce the number of dynamic lights casting shadows or switch some shadows to baked lighting
BIncrease the shadow resolution to make shadows clearer
CAdd more scripts to optimize shadow calculations
DDisable VSync to allow higher frame rates
Attempts:
2 left
💡 Hint
Think about what causes rendering spikes related to shadows.