[R] sleep timer resolution on OSX

ivo welch ivowel at gmail.com
Sat Jun 12 04:41:23 CEST 2010


I am doing some timing experiments.  To test looping performance, I
used the Sys.sleep function.  I noticed something in the docs that is
just a little misleading:

" The resolution of the time
     interval is system-dependent, but will normally be down to 0.02
     secs or better. (On modern Unix-alikes it will be better than
     1ms.)"

on OSX, which is (almost) a modern Unix-alike, and a very common platform,

> system.time( for (i in 1:100) Sys.sleep(0.001) )
   user  system elapsed
  0.005   0.004   1.020
> system.time( for (i in 1:100) Sys.sleep(0.01) )
   user  system elapsed
  0.005   0.004   1.019

so, the resolution seems to be about 0.01 seconds.  under linux,
similar time experiments show that the resolution is under 0.0001
seconds.

just wanted to put this into the r-archives for google searches.  (if
I could make changes to the docs, I would note it there instead.)

hope this helps someone else...

iaw

----
Ivo Welch (ivo.welch at brown.edu, ivo.welch at gmail.com)



More information about the R-help mailing list