Using the Unity profiler
The Unity3D engine comes with a full-featured profiler that's a great tool for dissecting everything that it's doing behind the scenes every frame. In this section, we'll write some functions that tax the processor and track them in the Unity profiler.
Create a new Unity project called PerformanceSandbox
. Save a scene called main.unity
in a new folder called Scenes
. Next, create a folder called Scripts
and create a new C# script in it named StressTestSystem
. When you're done, your Project window should look something like the following screenshot:
Now is a good time to add the Profiler window to your Editor layout. Select Profiler from the Window menu on the toolbar at the top of the editor. Add the window as a new tab next to the Scene window. It's a good idea to keep the Profiler window in a place where you can see it at the same time as your Game view, so you can see what Unity is rendering while you analyze it.
Tip
You can quickly open the profiler at any time...