<div dir="ltr">On Sun, Mar 4, 2018 at 8:09 AM Metin Akat <<a href="mailto:akat.metin@gmail.com">akat.metin@gmail.com</a>> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I haven't yet done rigorous testing with many processes, but what you are suggesting is the slowest so far (at least by the most naive way of measuring, while not under load) :<div><br></div><div><div>37> timer:tc(fun() -> lists:member({not_a_function, 1}, Module:module_info(exports)) end).</div><div>{514,false}</div><div>38> timer:tc(fun() -> try Module:not_a_function() catch error:undef ->  not_defined end end).</div><div>{47,not_defined}</div><div>39> timer:tc(fun() -> erlang:function_exported(Module, not_a_function, 1) end).</div><div>{8,false}</div></div><div><br></div></div></blockquote><br></div><div class="gmail_quote">Having looked a bit at this, the function in (38) is interpreted, not compiled. We can try this with eministat:<br><br>-module(function_exported).<br><br>-export([t/0, datasets/0]).<br><br>-define(ROUNDS, 10000).<br><br><br>v1() -><br>    v1(?ROUNDS).<br><br>v1(0) -> ok;<br>v1(N) -><br>    lists:member({not_a_function, 1}, ?MODULE:module_info(exports)),<br>    v1(N-1).<br><br>v2() -><br>    v2(?ROUNDS).<br><br>v2(0) -> ok;<br>v2(N) -><br>    try ?MODULE:not_a_function()<br>    catch<br>        error:undef -><br>            not_defined<br>    end,<br>    v2(N-1).<br><br>v3() -><br>    v3(?ROUNDS).<br><br>v3(0) -> ok;<br>v3(N) -><br>    _ = erlang:function_exported(?MODULE, not_a_function, 1),<br>    v3(N-1).<br><br>datasets() -><br>    [eministat:s("Variant 1",<br>                 fun v1/0, 50),<br>     eministat:s("Variant 2",<br>                 fun v2/0, 50),<br>     eministat:s("Variant 3",<br>                 fun v3/0, 50)].<br><br>t() -><br>    [H|T] = datasets(),<br>    eministat:x(95.0, H, T).<br><br><br></div><div class="gmail_quote">Running this yields:<br><br>2> function_exported:t().<br>x Variant 1<br>+ Variant 2<br>* Variant 3<br>+--------------------------------------------------------------------------+<br>|*          ++++++++                         x xxxxxxxxxxxxxx             x|<br>|*           ++++++                            x xxxxxxxx x                |<br>|*           ++++                              x x xxxx x x                |<br>|*           ++++                                  xxxx x x                |<br>|*           +++                                   xxx    x                |<br>|*           +++                                    xx    x                |<br>|*           +++                                    x     x                |<br>|*           +++                                    x                      |<br>|*           +++                                                           |<br>|*            ++                                                           |<br>|*            ++                                                           |<br>|*            ++                                                           |<br>|*            ++                                                           |<br>|*            +                                                            |<br>|*            +                                                            |<br>|*            +                                                            |<br>|*            +                                                            |<br>|*            +                                                            |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|*                                                                         |<br>|                                                |___MA___|                |<br>|            |MA|                                                          |<br>|A                                                                         |<br>+--------------------------------------------------------------------------+<br>Dataset: x N=50 CI=95.0000<br>Statistic     Value     [         Bias] (Bootstrapped LB‥UB)<br>Min:         1.46008e+5<br>1st Qu.      1.67652e+5<br>Median:      1.73901e+5<br>3rd Qu.      1.83833e+5<br>Max:         2.43860e+5<br>Average:     1.75521e+5 [      18.3119] (   1.71931e+5 ‥    1.80582e+5)<br>Std. Dev:    1.54033e+4 [     -419.011] (   1.12376e+4 ‥    2.45340e+4)<br><br>Outliers: 0/1 = 1 (μ=1.75539e+5, σ=1.49843e+4)<br>        Outlier variance:      0.604402 (severe, the data set is probably unusable)<br><br>------<br><br>Dataset: + N=50 CI=95.0000<br>Statistic     Value     [         Bias] (Bootstrapped LB‥UB)<br>Min:         3.74350e+4<br>1st Qu.      4.25210e+4<br>Median:      4.50860e+4<br>3rd Qu.      4.73290e+4<br>Max:         5.90190e+4<br>Average:     4.55904e+4 [     -12.9348] (   4.44757e+4 ‥    4.70025e+4)<br>Std. Dev:       4608.27 [     -81.7125] (      3694.90 ‥       5833.19)<br><br>Outliers: 0/3 = 3 (μ=4.55775e+4, σ=4526.56)<br>        Outlier variance:      0.665857 (severe, the data set is probably unusable)<br><br>Difference at 95.0% confidence<br>        -1.29931e+5 ± 4511.12<br>        -74.0257% ± 2.57013%<br>        (Student's t, pooled s = 1.13687e+4)<br>------<br><br>Dataset: * N=50 CI=95.0000<br>Statistic     Value     [         Bias] (Bootstrapped LB‥UB)<br>Min:            361.000<br>1st Qu.         365.000<br>Median:         367.000<br>3rd Qu.         369.000<br>Max:            848.000<br>Average:        386.060 [   1.53180e-2] (      372.960 ‥       423.160)<br>Std. Dev:       74.0183 [     -7.40628] (      26.8655 ‥       157.196)<br><br>Outliers: 0/6 = 6 (μ=386.075, σ=66.6120)<br>        Outlier variance:      0.873417 (severe, the data set is probably unusable)<br><br>Difference at 95.0% confidence<br>        -1.75135e+5 ± 4321.90<br>        -99.7800% ± 2.46232%<br>        (Student's t, pooled s = 1.08919e+4)<br>------<br><br>ok<br><br></div><div class="gmail_quote">So variant 2 is roughly 74% faster than variant 1.<br></div><div class="gmail_quote">And variant 3 is roughly 99.8% faster than variant 2.<br><br></div><div class="gmail_quote">I'll recommend variant 3. But you also have to measure more than a quick synthetic benchmark. Chances are that your other parts of the code is going to dominate to the point where wondering about this corner is futile.<br><br></div><div class="gmail_quote"><br></div></div>