[erlang-questions] os:timestamp/0 and erlang:now/0

Darach Ennis <>
Fri Mar 13 22:19:59 CET 2015


Hi Karolis,

I'm glad you've found the right path. :)

The benchmark you came up with might be interesting to the temporally
obsessed on this list (such as myself) if you think it is worth posting.

You may have stumbled onto something unexpected or surprising that would
be worth analysing further. However, micro-benchmarking can often result
in learning as much or more about micro-benchmarking than the target
under the microscope.

Cheers,

Darach.

On Fri, Mar 13, 2015 at 8:43 PM, Karolis Petrauskas <>
wrote:

> On Fri, Mar 13, 2015 at 9:41 PM, Darach Ennis <> wrote:
> > Hi Karolis,
> >
> > Out of curiosity, why are you comparing os:timestamp() to erlang:now()?
>
> I found a bug in my software, related to the system time. Then I
> noticed mismatch of time values in the log messages and log
> timestamps. I expected that erlang:now() >= os:timestamp() at any
> point in time, but that rendered to be false. That's why I decided to
> ask this question here. My bugfix ended up by not using system time in
> that place at all.
>
> > There is a possibility that frequent calls to erlang:now() runs ahead of
> the
> > clock as it must deliver unique values (guaranteed) whereas
> os:timestamp()
> > does not have this property. This alone may produce the behaviour you are
> > seeing independent of other variables (eg: +c).
>
> Yes, but I observe the opposite.
>
> > I wouldn't have considered either to be reasonably or easily comparable
> > against
> > each other. However, comparing one fun to precedent values returned by
> the
> > same fun should exhibit the relative behaviour you desire and correlate
> as
> > you
> > expect. But comparing os:timestamp to erlang:now doesn't seem supportable
> > as they behave differently by design.
>
> Yes, that was the cause for the bug. I was taking system time
> (erlang:now()), truncating milliseconds from it and therefore got
> rounding errors increased to unexpected level. The following
> investigation is just because of curiosity.
>
> > Hence, curious as to your use case and why you are comparing these two
> > distinct functions.
> >
> > Cheers,
> >
> > Darach.
>
> Karolis
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150313/8e8b3b51/attachment.html>


More information about the erlang-questions mailing list