[erlang-questions] erlang:now() vs os:timestamp()

Magnus Henoch <>
Wed Apr 3 19:18:18 CEST 2013


Magnus Henoch <> writes:

> https://gist.github.com/legoscia/5303050
>
> and now I get completely different results:
>
> os:timestamp =  0.36  0.15  0.17
> erlang:now   =  1.00  1.00  1.00

The very even results for erlang:now made me suspicious.  If you call
now() one million times, then that will obviously force the monotonic
clock to advance one million ticks, i.e. exactly one second.  I replaced
the now() call in epoch/0 with os:timestamp, and now the results are
much more even, though slightly in favor of os:timestamp:

os:timestamp =  0.33  0.15  0.17
erlang:now   =  0.31  0.26  0.30

I guess that's the lesson to learn: if you want unique values, use
now(), but if you want to know the actual time, use os:timestamp :)

Regards,
Magnus


More information about the erlang-questions mailing list