Skip to content

Instantly share code, notes, and snippets.

@fresky
Created June 8, 2013 07:36
Show Gist options
  • Save fresky/5734426 to your computer and use it in GitHub Desktop.
Save fresky/5734426 to your computer and use it in GitHub Desktop.
public static double TimeWatcher()
{
System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
watch.Start();
// operations under test start
// ...
// operation under test stop
watch.Stop();
var useTime = (double) watch.ElapsedMilliseconds/1000;
return useTime;
}
public static long MemoryWatcher()
{
long start = GC.GetTotalMemory(true);
// operations under test start
// ...
// operation under test stop
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