erlang:now() in erlang 4.9.1 on Linux

Ulf Wiger etxuwig@REDACTED
Thu Apr 20 14:25:44 CEST 2000

On Thu, 20 Apr 2000, Thomas Arts wrote:

>Ulf Wiger wrote:
>> This is a tricky issue, and it's certainly compounded by the fact
>> that erlang:now() *is* used both for unique IDs and for time
>> representation. There are basically two reasons for this:
>> I would like to see a new function, e.g. hrtime(), in Erlang, and
>> a shift in focus of erlang:now() to become a (strictly increasing)
>> internal real-time clock. It is vital that Erlang has a sense of
>> time that keeps ticking in one distinct direction, regardless of
>> what the system clock says.
>The problem cannot be solved by introducing a new function. The fact that
>now() presents the time in microseconds automatically implies that calls
>within microseconds will return the same value. If hardware gets faster,
>the risk of returning the same value increases.

Actually, introducing the new function was meant to solve the problem
that people need to use erlang:now() today in order to get sub-second
time accuracy. In most cases, one couldn't care less about
microseconds (knowing that the system time isn't that accurate
anyway!), but 1/1000, 1/100, 1/10 are useful quite often.
Naturally, for a hi-res clock, it would be quite logical to get the
same answer twice in a row, if the calls are close enough, and
if hrtime() had millisecond accuracy, it would indeed happen.
Of course, if it would return {Hr,Min,Sec}, where Sec : float(),
the precision could vary on different systems.

(With today's hardware, and using NTP, you can rely on your system
clock being accurate within a few milliseconds. A built-in GPS
circuit ought to be able to reach microsecond accuracy, I think...)

Currently, now() is used both as a "clocktick" counter and a hi-res
clock. This is unfortunate.

Ulf Wiger, Chief Designer AXD 301         <ulf.wiger@REDACTED>
Ericsson Telecom AB                          tfn: +46  8 719 81 95
Varuvägen 9, Älvsjö                          mob: +46 70 519 81 95
S-126 25 Stockholm, Sweden                   fax: +46  8 719 43 44

More information about the erlang-questions mailing list