[erlang-questions] now/0 resolution
Tue Sep 11 04:49:22 CEST 2007
Raimo Niskanen wrote:
> On Fri, Sep 07, 2007 at 07:23:34AM -0500, Serge Aleynikov wrote:
>> Since according to documentation consecutive executions of now/0 will
>> return different values (with microsecond precision) I have two questions:
>> 1. Does it mean that inserting now/0 calls in code will slow down
>> execution to 1mks per execution? If not, then performance of function
>> call measured using now/0 time stamping would be inaccurate.
> Well, no on both alternatives. The return value from now/0 is bumped
> with 1 us for every call to always return an incrementing value. But
> it is hardly a problem - it will not be noticabely inaccurate.
> To make now/0 off by more than 1 us you will have to call it so often,
> more than once per us, that it becomes impractical.
I need to measure the time it takes for a UDP packet to get delivered to
the application space from the point it's received by the kernel (using
SO_TIMESTAMP socket option) as accurately as possible (~ 1 us resolution).
> To time a function call you also can use call trace with
> timestamps. Then on some platforms (Solaris (and Linux?))
> you have the option to count CPU time instead.
So far I've been using successive now/0 calls in selected parts of
function to measure execution times. Doesn't the call trace slow down
> The high resolution timer is actually used for timekeeping by now/0
> and tracing, but the nanoseconds are not available in any API.
If I wanted to take advantage of the hr timer in a linked-in driver
which function would you recommend to call?
More information about the erlang-questions