Skip to content

Instantly share code, notes, and snippets.

@mstevenson
Created February 4, 2015 10:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mstevenson/febc688c5cf1af4e1c6e to your computer and use it in GitHub Desktop.
Save mstevenson/febc688c5cf1af4e1c6e to your computer and use it in GitHub Desktop.
Unity tool for measuring execution time
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// Debugging tools
/// </summary>
public static class Instruments
{
static string stopwatchName;
static System.Diagnostics.Stopwatch stopwatch;
[System.Diagnostics.Conditional ("UNITY_EDITOR")]
public static void BeginStopwatch (string name)
{
if (stopwatch == null) {
stopwatch = new System.Diagnostics.Stopwatch();
}
stopwatchName = name;
stopwatch.Stop ();
stopwatch.Reset ();
stopwatch.Start ();
}
[System.Diagnostics.Conditional ("UNITY_EDITOR")]
public static void EndStopwatch ()
{
stopwatch.Stop ();
var time = (stopwatch.ElapsedTicks / (double)System.Diagnostics.Stopwatch.Frequency) * 1000;
Debug.Log ("[Instruments] " + stopwatchName + ": " + time + " ms");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment