Benchmarking and Profiling

Benchmarking is the process of conducting reproducible performance tests to see how fast an application is running. It may involve coding the same task two different ways and seeing which one runs faster. The web page shown previously in Example 17-9, which tested the relative speed of string concatenation techniques, is an example of a simple benchmarking program. Obviously, benchmarking programs will often be more complex than that example. You should design them to emulate your environment as closely as possible.

Profiling is the gathering of performance information about an application. There are several ways to profile an application. Two that are part of the .NET Framework are the following:

  • Windows XP and Windows Vista System Performance Monitor

  • The .NET performance counters API

You can use the Performance Monitor to watch a huge variety of system parameters, both .NET-specific and otherwise, in real time. You can open the Performance Monitor by opening a Command Prompt and typing in perfmon. When the Performance Monitor opens, click the Add icon on the Toolbar to select and add any number of performance counters. The available counters cover the processor, memory, hard disk, SQL Server, .NET, and ASP.NET.

The performance counter’s API includes several classes. You can use the PerformanceCounter component in the System.Diagnostics namespace for reading existing performance counters and for creating and writing to custom counters.

Tip

Benchmarking is a ...

Get Programming ASP.NET 3.5, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.