Skip to content

Instantly share code, notes, and snippets.

@twobob
Forked from mstevenson/Instruments.cs
Created April 15, 2017 03:18
Show Gist options
  • Save twobob/f0b73e973f0c21e76955d2d86d521e5b to your computer and use it in GitHub Desktop.
Save twobob/f0b73e973f0c21e76955d2d86d521e5b 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