[erlang-questions] non-linear behavior?
Zoltan Lajos Kis
kiszl@REDACTED
Sat May 15 14:06:18 CEST 2010
On 5/15/2010 1:56 PM, Roberto Ostinelli wrote:
> dear list,
>
> while performing some optimization tests i found a behavior which i
> cannot understand. i've stripped it down to a very simple test module.
>
> here it is:
>
> %%%%%%%%%%%%%%%%%%%%%%%%%
>
> -module(lintest).
> -compile(export_all).
>
> start() ->
> C1 = 100000000,
> C2 = 1000000000,
> {M1, _} = timer:tc(?MODULE, decrease, [C1]),
> {M2, _} = timer:tc(?MODULE, decrease, [C2]),
> io:format("decrease from ~p took ~p seconds.",[C1, M1/1000000]),
> io:format("decrease from ~p took ~p seconds.",[C2, M2/1000000]).
>
> % computational processes
> decrease(0) -> ok;
> decrease(N) -> decrease(N - 1).
>
> %%%%%%%%%%%%%%%%%%%%%%%%%
>
> if you run this module, you'll get:
>
>
> roberto$ erl
> Erlang R13B04 (erts-5.7.5) [source] [smp:4:4] [rq:4] [async-threads:0]
> [hipe] [kernel-poll:true]
>
> Eshell V5.7.5 (abort with ^G)
> 1> c(lintest).
> {ok,lintest}
> 2> lintest:start().
> decrease from 100000000 took 0.813727 seconds.
> decrease from 1000000000 took 46.831207 seconds.
> ok
> 3>
>
> this yields the same results with/without kernel poll, and smp disabled/enabled.
>
> i might be missing a point here, but shouldn't this be a linear
> computation? if it took 0.8 seconds to count down from 100,000,000
> shouldn't it take around 10 times more to count down from
> 1,000,000,000, i.e. around 8 seconds? the resulting 46 seconds seems
> way strange to me.
>
> any kind soul can explain me what i am missing here?
>
> thank you,
>
> r.
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>
A probable explanation is that integers longer than 28 bits
(134,217,727) are represented, and probably handled differently from
those below this limit.
Zoltan.
More information about the erlang-questions
mailing list