Created
July 21, 2017 22:20
-
-
Save gluschenko/7b42d22c15c63d47242963f54b524f94 to your computer and use it in GitHub Desktop.
C# execution timer
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 System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
public class TimeMachine | |
{ | |
public static Dictionary<string, Stopwatch> Timers = new Dictionary<string, Stopwatch>(); | |
public static void Start(string name) | |
{ | |
if (!Timers.ContainsKey(name)) | |
{ | |
Stopwatch T = Stopwatch.StartNew(); | |
Timers.Add(name, T); | |
} | |
else | |
{ | |
Stopwatch T = Timers[name]; | |
T.Reset(); | |
T.Start(); | |
} | |
} | |
public static void Dump(string name) | |
{ | |
if (Timers.ContainsKey(name)) | |
{ | |
long microseconds = Timers[name].ElapsedTicks / (TimeSpan.TicksPerMillisecond / 1000); | |
UnityEngine.Debug.Log(name + ": " + | |
microseconds + " μs | " + | |
Timers[name].ElapsedMilliseconds + " ms | " + | |
Timers[name].ElapsedTicks + " ticks"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment