Skip to content

Instantly share code, notes, and snippets.

@r618
Created October 24, 2015 14:47
Show Gist options
  • Save r618/6e651c71fe18e51e054f to your computer and use it in GitHub Desktop.
Save r618/6e651c71fe18e51e054f to your computer and use it in GitHub Desktop.
builint profiler usage in Unity
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