About DOpus.Delay() value

One time, when I needed to add a very short delay (2 ms), I noticed that the actual delay is almost never the same as the requested one, but instead is usually bigger, more noticeable when the used value is very small. Why is that? You might think it's because of the JScript engine or something related, but if I use -1 (which I assume means no delay), it consistently takes 0 ms.

For example:


var ini;
var t = [-1,2,10,100,1000];
for (var i = 0; i < t.length;i++){
	ini = new Date();
	DOpus.Delay(t[i]);
	DOpus.Output( t[i] +' ms delay expected => '+(new Date()-ini)+'ms received');
}

It depends when Windows reschedules the thread that asked to be paused for a while. The OS is not that accurate and may wake things slightly earlier or later.

There are ways to have more accurate timers, but they're much more resource intensive and don't make sense for most things.