Skip to content

Instantly share code, notes, and snippets.

@gluschenko
Created July 21, 2017 22:20
Show Gist options
  • Save gluschenko/7b42d22c15c63d47242963f54b524f94 to your computer and use it in GitHub Desktop.
Save gluschenko/7b42d22c15c63d47242963f54b524f94 to your computer and use it in GitHub Desktop.
C# execution timer
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