erlang:now() in erlang 4.9.1 on Linux

matthias@REDACTED matthias@REDACTED
Thu Apr 20 11:34:16 CEST 2000

 > Pekka.Hedqvist@REDACTED wrote:

 > >When trying to measure time we get really weird values from the
 > >'erlang:now()' when two successive calls to it are done with less than
 > >100 microseconds between the two calls. The values are far too low; 0,
 > >1 microseconds are reported even when maybe 60-80 has passed. If the

Per writes:

 > Do you really ever see a difference of 0 microseconds? That would be a
 > serious bug, monotonically increasing values is just about the only
 > thing erlang:now() *really* promises to produce. 

Careful! "monotonic" doesn't mean what you use it to mean, I think. (*)

The authors of the standard erlang spec write:

    A 3-tuple of integers is returned that is guaranteed to be
    different for each invocation on a node.
    Two calls of the BIF now() by a processes residing on the same
    node can never return the same term.
    (footnote)However, the time might be inaccurate if several calls
    are made within a microsecond.	

The behaviour Pekka is seeing is wrong, though I think that the
uniqueness requirement on now() should be removed. If you want
something unique, use make_ref(). If you want to know the time, call
now() (or time()).

I can imagine future hardware where keeping now() both unique from
call to call AND more or less representing the time becomes difficult.


* As to meaning of monotonic...

The erlang man page for now() doesn't say "monotonic", it says
"continously increasing". I'll leave it to your imagination what that
means when you're talking about a discrete function...

monotonic, according to my recollections from uni and also Cormen, 
Leiserson & Rivest, "Introduction to Algorithms", p.32 means

	 A function f(n) is monotonically increasing if m =< n imples
	 f(m) =< f(n).

The implicit argument to now() is "the time", so to satisfy
monotonically increasing, I could implement now() as

      now() -> {0,0,0}

This confusion about the meaning of "monotonically increasing" seems
widespread in computer science, e.g. both RFC2747 and RFC1644 use it
when they mean "strictly increasing". Does anyone know where this
(wrong?) use originated?


More information about the erlang-questions mailing list