Created
March 31, 2023 12:10
-
-
Save J-Swift/1ed915fce585a87dde6ad2f3ab3dbff5 to your computer and use it in GitHub Desktop.
Drop in utility for profiling some code
This file contains 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
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