Last active
September 3, 2022 05:59
-
-
Save fresky/5734434 to your computer and use it in GitHub Desktop.
Time/Memory watcher for C#
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 double TimeWatcher(Action action) | |
{ | |
System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); | |
watch.Start(); | |
action(); | |
watch.Stop(); | |
var useTime = (double) watch.ElapsedMilliseconds/1000; | |
return useTime; | |
} | |
public static long MemoryWatcher(Action action) | |
{ | |
long start = GC.GetTotalMemory(true); | |
action(); | |
GC.Collect(); | |
GC.WaitForFullGCComplete(); | |
long end = GC.GetTotalMemory(true); | |
long useMemory = (end - start)/(1024*1024); | |
return useMemory; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment