-
-
Save twobob/f0b73e973f0c21e76955d2d86d521e5b to your computer and use it in GitHub Desktop.
Unity tool for measuring execution time
This file contains hidden or 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.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