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)<div><br></div><div>Also you can test it yourself like this</div>
<div><br></div><div><div>33> F1 = fun lists:sort/1.                            </div><div>#Fun<lists.sort.1></div><div>34> F = fun(A)-> lists:sort(A) end.                   </div><div>#Fun<erl_eval.6.80247286></div>
<div>35> F1 = fun lists:sort/1.         </div><div>#Fun<lists.sort.1></div><div>36> timer:tc(erlang, apply, [F, [[2,3,5,1,10,9,8]]]).</div><div>{11,[1,2,3,5,8,9,10]}</div><div>37> timer:tc(erlang, apply, [F1, [[2,3,5,1,10,9,8]]]).</div>
<div>{4,[1,2,3,5,8,9,10]}</div><div><br></div><div>Anyone shall correct me if i'm wrong please :)</div><br><div class="gmail_quote">On Tue, Nov 1, 2011 at 6:02 PM, Filipe David Manana <span dir="ltr"><<a href="mailto:fdmanana@apache.org">fdmanana@apache.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Is there any difference, regarding performance/efficiency, between the<br>
2 following calls:<br>
<br>
1)<br>
<br>
F = fun(A, B) -> myfun(A, B) end,<br>
F(foo, bar).<br>
<br>
<br>
2)<br>
<br>
F = fun mymodule:myfun/2,<br>
F(foo, bar).<br>
<br>
I've heard about the later being more efficient, but haven't been able<br>
to measure it (using timer:tc/3). Or is this part of the eight myths<br>
(<a href="http://www.erlang.org/doc/efficiency_guide/myths.html" target="_blank">http://www.erlang.org/doc/efficiency_guide/myths.html</a>) ?<br>
<br>
Thanks<br>
<font color="#888888"><br>
--<br>
Filipe David Manana,<br>
<br>
"Reasonable men adapt themselves to the world.<br>
 Unreasonable men adapt the world to themselves.<br>
 That's why all progress depends on unreasonable men."<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</font></blockquote></div><br><br clear="all"><div><br></div>-- <br>Best Regards,<br>- Ahmed Omar<div><a href="http://nl.linkedin.com/in/adiaa" target="_blank">http://nl.linkedin.com/in/adiaa</a></div><div>Follow me on twitter</div>
<div><a href="http://twitter.com/#!/spawn_think" target="_blank">@spawn_think</a></div><br>
</div>