Reputation: 2333
iex(1)> a = :erlang.timestamp
{1458, 585479, 931609}
iex(2)> b = :erlang.timestamp
{1458, 585484, 197713}
iex(3)> :erlang.now_diff(a,b)
** (UndefinedFunctionError) undefined function: :erlang.now_diff/2
:erlang.now_diff({1458, 585479, 931609}, {1458, 585484, 197713})
So I can access erlang functions in elixir, accessing them by :erlang
, but now_diff/2 is undefined.
I have a thought that this timer is not standard erlang module, and needed to be required/imported, but I can't figure out how?
P.S. Don't advice timex instead if it doesn't have function to calculate timestamps diff with high precision like this erlang function. I didn't find reading docs.
Upvotes: 0
Views: 1566
Reputation: 1637
Use
:timer.now_diff(a, b)
Functions are not prefixed with :erlang
because they are erlang functions, but because they are part of the erlang
module. now_diff is part of the timer module, hence you would use :timer
instead of :erlang
.
Upvotes: 5