Skip to content

Instantly share code, notes, and snippets.

@J-Swift
Created March 31, 2023 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save J-Swift/1ed915fce585a87dde6ad2f3ab3dbff5 to your computer and use it in GitHub Desktop.
Save J-Swift/1ed915fce585a87dde6ad2f3ab3dbff5 to your computer and use it in GitHub Desktop.
Drop in utility for profiling some code
public static class ProfilingService
{
private static Stopwatch? watch = null;
public static void StartMeasure()
{
lastMillis = 0;
watch = System.Diagnostics.Stopwatch.StartNew();
System.Console.WriteLine($"[START]");
}
public static void StopMeasure()
{
watch.Stop();
var millis = watch.ElapsedMilliseconds;
System.Console.WriteLine($"[END] {millis}ms");
}
private static long lastMillis = 0;
public static void Measure(string tag)
{
var millis = watch.ElapsedMilliseconds;
System.Console.WriteLine($" > [P {tag}] {millis - lastMillis}ms");
lastMillis = millis;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment