Linux timer accuracy graphs and comparison,

Hi,
I have compared the accuracy given by SDL_Delay() on Linux 2.4.7, and
plotted actual vs requested delay for a few different cases.

The results can be found at

http://www.ifm.liu.se/~ulfek/projects/timers/

The best way to get accurate timers on current Linux systems
seems to be with a function like

void busy_delay(unsigned long dt)
{
unsigned long target = SDL_GetTicks() + dt;
if (dt > 10)
SDL_Delay((dt/10)*10 - 1);
while (SDL_GetTicks() < target) {}
}

But I don’t know if there are better ways to busy-wait.
It is also a bit ugly since it assumes a timer resolution of 10 ms,
and wastes CPU time if the resolution is actually greater.

I don’t know how these figures compare to other operating systems and
machines.

–ulf

Ulf Ekstr?m, currently at CNR in Pisa, Italy
http://www.ifm.liu.se/~ulfek