<div>Hi</div><div>As I read the<font __editorwarp__="1" style="display: inline; font-size: 14px; font-family: Verdana; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; background-color: rgba(0, 0, 0, 0);"> </font><font __editorwarp__="1" style="display: inline; font-size: 14px; font-family: Verdana; color: rgb(0, 0, 0); font-weight: normal; background-color: rgba(0, 0, 0, 0);"><i>Efficiency Guide</i></font><font __editorwarp__="1" style="display: inline; font-size: 14px; font-family: Verdana; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; background-color: rgba(0, 0, 0, 0);">, I found something interesting:(see <a href="http://www.erlang.org/doc/efficiency_guide/functions.html#id67357">http://www.erlang.org/doc/efficiency_guide/functions.html#id67357</a>)</font></div><div><blockquote style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: medium; line-height: normal;"><font __editorwarp__="1" style="display: inline; font-size: 14px; font-family: Verdana; font-weight: normal; font-style: normal; background-color: rgba(0, 0, 0, 0);" color="#0000ff">Here is an intentionally rough guide to the relative costs of different kinds of calls. It is based on benchmark figures run on Solaris/Sparc:</font><ul style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: medium; line-height: normal;"><li style="display: list-item; font-size: 14px; font-family: Verdana; font-weight: normal; font-style: normal; background-color: rgba(0, 0, 0, 0);"><font color="#0000ff">Calls to local or external functions (foo(), m:foo()) are the fastest kind of calls.</font></li></ul><ul style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: medium; line-height: normal;"><li style="display: list-item; font-size: 14px; font-family: Verdana; font-weight: normal; font-style: normal; background-color: rgba(0, 0, 0, 0);"><font color="#0000ff">Calling or applying a fun (Fun(), apply(Fun, [])) is about </font><font color="#ff0000">three times</font><font color="#0000ff"> as expensive as calling a local function.</font></li></ul><ul style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: medium; line-height: normal;"><li style="display: list-item; font-size: 14px; font-family: Verdana; font-weight: normal; font-style: normal; background-color: rgba(0, 0, 0, 0);"><font color="#0000ff">Applying an exported function (Mod:Name(), apply(Mod, Name, [])) is about twice as expensive as calling a fun, or about </font><font color="#ff0000">six times</font><font color="#0000ff"> as expensive as calling a local function.</font></li></ul></blockquote><p style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: medium; line-height: normal;"></p><font __editorwarp__="1" style="display: inline; font-size: 14px; font-family: Verdana; font-weight: normal; font-style: normal; background-color: rgba(0, 0, 0, 0);"><div style="color: rgb(0, 0, 0);">But I get another result when I run these code in my computer:</div><blockquote formatblock="1" style="margin: 0.8em 0px 0.8em 2em; padding: 0px 0px 0px 0.7em; border-left-width: 2px; border-left-style: solid; border-left-color: rgb(221, 221, 221);">foo() -><br>    ok.<br>test() -><br>    List = lists:seq(1, 50000000),<br>    statistics(wall_clock),<br>    statistics(runtime),<br><font color="#0000ff">    %% [foo() || _ <- List],                               %%test result 358 ~ 358<br></font><font color="#0000ff">    %% [?MODULE:foo() || <span style="line-height: 1.5; background-color: rgba(0, 0, 0, 0);">_ <- List</span><span style="line-height: 1.5; background-color: rgba(0, 0, 0, 0);">],                </span><span style="line-height: 1.5; background-color: rgba(0, 0, 0, 0);">%%test result 358 ~ 358<br></span></font><font color="#0000ff"><span style="line-height: 1.5; background-color: rgba(0, 0, 0, 0);">    %% [apply(?MODULE, foo, [] || </span><span style="line-height: 1.5; background-color: rgba(0, 0, 0, 0);">_ <- List</span><span style="line-height: 1.5; background-color: rgba(0, 0, 0, 0);">],     </span><span style="line-height: 1.5; background-color: rgba(0, 0, 0, 0);">%%test result 358 ~ 358<br></span></font><span style="line-height: 1.5; background-color: rgba(0, 0, 0, 0);"><font color="#0000ff">   </font> </span><span style="line-height: 1.5; background-color: rgba(0, 0, 0, 0);">[apply(fun() -> ok end, []) || </span><span style="line-height: 1.5; background-color: rgba(0, 0, 0, 0);">_ <- List</span><span style="line-height: 1.5; background-color: rgba(0, 0, 0, 0);">],   <font color="#0000ff">      %%test result 2247 ~ 1716</font><br></span><span style="line-height: 1.5; background-color: rgba(0, 0, 0, 0);"><font color="#0000ff">    </font>{_, Time1} = statistics(</span><span style="line-height: 1.5;">wall_clock),<br></span><span style="line-height: 1.5;">    </span><span style="line-height: 1.5;">{_, Time2} =</span><span style="line-height: 1.5;"> </span><span style="line-height: 1.5;">statistics(runtime),<br></span><span style="line-height: 1.5;">    io:format("calc ~p ~~ ~p~n", [Time1, Time2]).</span></blockquote><div>Applying a fun is even slower than apply/3, Why?</div><div><span style="line-height: 1.5;">I also notice "</span><font __editorwarp__="1" style="display: inline; font-size: 14px; font-family: Verdana; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; background-color: rgba(0, 0, 0, 0);">apply/3 must look up the code for the function to execute in a hash table. Therefore, it will always be slower than a direct call or a fun call".</font><span style="line-height: 1.5;"><br>So I test in my project which include many modules and I get the same result.</span></div></font></div>