Skip to content

Instantly share code, notes, and snippets.

@azborgonovo
Created August 4, 2020 13:15
Show Gist options
  • Save azborgonovo/3ca45dec202f04f0294ece8d816944fe to your computer and use it in GitHub Desktop.
Save azborgonovo/3ca45dec202f04f0294ece8d816944fe to your computer and use it in GitHub Desktop.
Performance logging
var before0 = GC.CollectionCount(0);
var before1 = GC.CollectionCount(1);
var before2 = GC.CollectionCount(2);
var sw = Stopwatch.StartNew();
// Do...
sw.Stop();
Console.WriteLine($"\nTime: {sw.ElapsedMilliseconds} ms");
Console.WriteLine($"# Gen0: {GC.CollectionCount(0) - before0}");
Console.WriteLine($"# Gen1: {GC.CollectionCount(1) - before1}");
Console.WriteLine($"# Gen2: {GC.CollectionCount(2) - before2}");
Console.WriteLine($"Memory: {Process.GetCurrentProcess().WorkingSet64 / 1024 / 1024} mb");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment