[erlang-questions] Anonymous functions and performance
Ahmed Omar
spawn.think@REDACTED
Tue Nov 1 18:32:31 CET 2011
I would expect the later to be more efficient as it's just a symbolic
reference to the function (and it'll also all the time call the latest
version of your module unlike anonymous fun)
Also you can test it yourself like this
33> F1 = fun lists:sort/1.
#Fun<lists.sort.1>
34> F = fun(A)-> lists:sort(A) end.
#Fun<erl_eval.6.80247286>
35> F1 = fun lists:sort/1.
#Fun<lists.sort.1>
36> timer:tc(erlang, apply, [F, [[2,3,5,1,10,9,8]]]).
{11,[1,2,3,5,8,9,10]}
37> timer:tc(erlang, apply, [F1, [[2,3,5,1,10,9,8]]]).
{4,[1,2,3,5,8,9,10]}
Anyone shall correct me if i'm wrong please :)
On Tue, Nov 1, 2011 at 6:02 PM, Filipe David Manana <fdmanana@REDACTED>wrote:
> Is there any difference, regarding performance/efficiency, between the
> 2 following calls:
>
> 1)
>
> F = fun(A, B) -> myfun(A, B) end,
> F(foo, bar).
>
>
> 2)
>
> F = fun mymodule:myfun/2,
> F(foo, bar).
>
> I've heard about the later being more efficient, but haven't been able
> to measure it (using timer:tc/3). Or is this part of the eight myths
> (http://www.erlang.org/doc/efficiency_guide/myths.html) ?
>
> Thanks
>
> --
> Filipe David Manana,
>
> "Reasonable men adapt themselves to the world.
> Unreasonable men adapt the world to themselves.
> That's why all progress depends on unreasonable men."
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
--
Best Regards,
- Ahmed Omar
http://nl.linkedin.com/in/adiaa
Follow me on twitter
@spawn_think <http://twitter.com/#!/spawn_think>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111101/490413a0/attachment.htm>
More information about the erlang-questions
mailing list