Inside the static Stopwatch
constructor we can see the following code, that basicly checks whether a high-resolution performance counter exists.
static Stopwatch()
{
if (!SafeNativeMethods.QueryPerformanceFrequency(out Frequency))
{
IsHighResolution = false;
Frequency = 0x989680L;
tickFrequency = 1.0;
}
else
{
IsHighResolution = true;
tickFrequency = 10000000.0;
tickFrequency /= (double) Frequency;
}
}
On MSDN it says about QueryPerformanceFrequency
:
Retrieves the frequency of the high-resolution performance counter, if one exists
It's pretty unclear, however, when exactly does it exist? I suspect it usually exists on current machines, but when exactly doesn't it?
It's interesting because when it doesn't exist, Stopwatch
becomes a mere wrapper around the DateTime.UtcNow
property.