IsHighResolution

suggest change
// Display the timer frequency and resolution.
if (Stopwatch.IsHighResolution)
{
    Console.WriteLine("Operations timed using the system's high-resolution performance counter.");
}
else 
{
    Console.WriteLine("Operations timed using the DateTime class.");
}

long frequency = Stopwatch.Frequency;
Console.WriteLine("  Timer frequency in ticks per second = {0}",
    frequency);
long nanosecPerTick = (1000L*1000L*1000L) / frequency;
Console.WriteLine("  Timer tick is {0} nanoseconds", 
    nanosecPerTick);

https://dotnetfiddle.net/ckrWUo

The timer used by the Stopwatch class depends on the system hardware and operating system. IsHighResolution is true if the Stopwatch timer is based on a high-resolution performance counter. Otherwise, IsHighResolution is false, which indicates that the Stopwatch timer is based on the system timer.

Stopwatch ticks depend on the machine and operating system, so the ratio of ticks to seconds can differ between systems, and possibly even on the same system after a reboot. A Stopwatch tick is not the same interval as a DateTime or TimeSpan tick.

To get a system-independent duration, use Elapsed or ElapsedMilliseconds. Those properties already account for Frequency (ticks per second).

Prefer Stopwatch to DateTime when measuring elapsed time. It uses DateTime only when it can't use a high-resolution performance counter.

Source

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents