This question mostly for education. I just interested why. I’m using program from here but modified it a little bit:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
long ticks = DateTime.Now.Ticks;
while(true)
{
if (ticks != DateTime.Now.Ticks)
{
long newTicks = DateTime.Now.Ticks;
Console.WriteLine(newTicks - ticks);
ticks = newTicks;
}
else
{
Console.WriteLine("same");
}
}
}
}
}
Results:
600$ Lenovo Edge 11, Intel Pentium U5400, Windows 7 Home Basic
same
same
same
same
same
same
same
10000
same
same
10000$ HP DL360p Gen8 2 * Xeon E5-2640, Windows Server 2008 R2
same
same
same
same
same
same
same
156001
same
same
same
same
same
same
same
same
same
same
same
same
So the precision of the DateTime on the cheap notebook is 10 ms, expensive server hardware has precision of 156 ms.
Why? I guess probably Windows 7 is more “precise” than Windows Server 2008 R2, but this is just my guess. On both computers latest .NET framework with all updated and all windows updates are installed.
First of all, you miscalculated:
So 10000 ticks are just 1ms, and 156001 ticks are 15.6ms.
That difference is not in the hardware. By default windows runs a certain internal timer approximately every 16ms. This timer is responsible for many timing related features in windows, including Timers,
Environment.TickCount,Thread.SleepandDateTime.UtcNow.Any application can reduce this to a chosen number of milliseconds (i.e. 1ms minimum) using the
timeBeginPeriodAPI. It seems like an application running on your notebook has requested higher precision, but no application running on your server has.It’s not active by default, because it has some negative side-effects. For example higher power consumption when the computer is idling, because it can only sleep for 1ms intervals instead of 16ms intervals.