Reputation: 31
Does anybody know if it is possible to make a high resolution timer in Erlang?
According to documentation all timers and timeouts are measured in milliseconds.
There is need to make a delay in microseconds. For example, instead of
timer:apply_after(MilliSec, Module, Function, Arguments).
something like
timer:apply_after(MicroSec, Module, Function, Arguments).
Upvotes: 3
Views: 2210
Reputation: 387
Upvotes: -1
Reputation: 6347
Indeed, all timers and timeouts primitives are in milliseconds including :
receive
... after
primitive (which is what timer
module eventually relies upon);erlang:send_after/3
and erlang:start_timer/3
which rely on the same mechanism;driver_set_timer
function for linked in drivers.Two methods could be considered to achieve a sub-millisecond timer:
erlang:now()
is not a real time function as it is guaranteed to be monotonous (and this is quite expensive). You should use os:timestamp()
instead;Upvotes: 3