[erlang-questions] erlang:now() vs os:timestamp()
Wed Apr 3 18:41:02 CEST 2013
Many things are missing in the benchmark, one of which is concurrency
The calls you make are purely sequential, and you'll have pretty much no
lock contention on there.
now() is a monotonic function that always increases and thus requires a
global lock to read. It's generally very fast, but calling it hundreds
of times per second over thousands of processes is going to be worse
than calling os:timestamp() assuming your system doesn't add such a lock
to the os:timestamp() call.
I'd have to agree with the advice -- in practice, I tend to avoid using
now() and use os:timestamp(), unless I know I want my time to be
monotonic (and unique, albeit predictable).
On 04/03, Manuel A. Rubio "Bombadil" wrote:
> I saw a keynote from Rick Reed (WhatsApp) and he said: "Prefer
> os:timestamp to erlang:now"... I did a benchmark to test it, and
> get the following results:
> os:timestamp = 1.44 1.38 1.38
> erlang:now = 1.01 1.00 1.00
> I know that he says "prefer" and not "better"... but the benchmark
> says that he should be say the opposite :-P
> What do you think?
>  http://www.erlang-factory.com/upload/presentations/558/efsf2012-whatsapp-scaling.pdf
>  https://gist.github.com/manuel-rubio/5302361
> Manuel Rubio.
> erlang-questions mailing list
More information about the erlang-questions