Created
October 24, 2015 14:47
-
-
Save r618/6e651c71fe18e51e054f to your computer and use it in GitHub Desktop.
builint profiler usage in Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Runtime.CompilerServices; | |
public class Tester : MonoBehaviour | |
{ | |
const int kRuns = 10000000; | |
const string | |
kDirectSampleName = "Direct", | |
kCachedSampleName = "Cached"; | |
Transform m_Cached; | |
IEnumerator Start () | |
{ | |
m_Cached = transform; | |
Profiler.enabled = true; | |
yield return null; | |
Profiler.BeginSample (kDirectSampleName); | |
for (int test = 0; test < kRuns; ++test) | |
{ | |
TestDirect (); | |
} | |
Profiler.EndSample (); | |
Profiler.BeginSample (kCachedSampleName); | |
for (int test = 0; test < kRuns; ++test) | |
{ | |
TestCached (); | |
} | |
Profiler.EndSample (); | |
yield return null; | |
Profiler.enabled = false; | |
Debug.Break (); | |
} | |
[MethodImpl (MethodImplOptions.NoInlining)] | |
void TestDirect () | |
{ | |
transform.hasChanged = !transform.hasChanged; | |
} | |
[MethodImpl (MethodImplOptions.NoInlining)] | |
void TestCached () | |
{ | |
m_Cached.hasChanged = !m_Cached.hasChanged; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment