
Comparing Retrieval Methods
Retrieving a raw value with the RawValue property is very quick, because no calculations or comparisons are performed. For example, if you are using a counter simply to count the number of orders processed in a system, you can retrieve the counter's raw value. For more information on retrieving raw values, see How to: Retrieve Raw Performance Counter Values.
Retrieving a calculated value with the NextValue method is often more useful than retrieving the raw value, but this value may also give you an unrealistic view of the data because it can reflect unusual fluctuations in the data at the moment when the value is calculated. For example, if you have a counter that calculates the orders processed per second, an unusually high or low amount of orders processed at one particular moment will result in an average that is not realistic over time. This may provide a distorted view of the actual performance of your system. For more information on retrieving a calculated value, see How to: Retrieve Calculated Performance Counter Values.
Samples provide the most realistic views of the data in your system by allowing you to retrieve, retain, and compare various values over time. You would retrieve a sample, using the NextSample method, if you needed to compare values in different counters or calculate a value based on raw data. This may be slightly more resource-intensive, however, than a NextValue call. For more information on retrieving a sample, see How to: Retrieve Performance Counter Samples.
The NextSample method returns an object of type CounterSample. When you retrieve a sample, you have access to properties on the CounterSample class such as RawValue, BaseValue, TimeStamp, and SystemFrequency. These properties let you get a very detailed look at the data that makes up the sample data.