System.Diagnostics Articles

Using the .NET Stopwatch class to Profile Your Code

The Stopwatch class in the System.Diagnostics namespace can be used a as a basic tool to profile blocks of .NET code. System.Diagnostics.Stopwatch timerObj = new System.Diagnostics.Stopwatch(); timer.Start(); Decimal totalDec = 0; int limit = 1000000; for (int i = 0; i < limit; ++i) { totalDec = totalDec + (Decimal)Math.Sqrt(i); } timerObj.Stop(); Console.WriteLine(“Sum of square […]

Read more

Measure Memory Usage of .NET Applications

There are two main methods for measuring the memory usage of a .NET application, using the GC class or using System.Diagnostics Retrieve Your App’s Memory Utilization using the GC class The .NET Framework’s GC class contains many useful memory-related methods, including GetTotalMemory(), which returns the amount of memory the garbage collector believes is allocated to […]

Read more