[erlang-questions] Minimum time for timer:sleep()?

James Hague james.hague@REDACTED
Sun Mar 18 23:46:13 CET 2007

Here's some simple code to test timer:sleep/1:

test(Milliseconds) ->
   T1 = now(),
   T2 = now(),
   io:fwrite("elapsed: ~w\n", [timer:now_diff(T2, T1)]).

On the recent model MacBook I tested this on, test(5) prints "elapsed:
10182".  In fact, any value less than 10 milliseconds sleeps for ~10
milliseconds.  Considering that a message send/receive pair is
measured in single-digit MICROseconds on the same machine, this is
curious to me.   Does anyone have any insight into this behavior?

(FWIW, timer:sleep/1 is implemented as a single receive statement.)


More information about the erlang-questions mailing list