[erlang-questions] non-linear behavior?

Roberto Ostinelli roberto@REDACTED
Sat May 15 14:24:41 CEST 2010


2010/5/15 Zoltan Lajos Kis <kiszl@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.

thank you zoltan, this is it, and here below is proof.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

-module(lintest2).
-compile(export_all).

start() ->
	C = 100000000,
	T1 = 1,
	T2 = 10,
	{M1, _} = timer:tc(?MODULE, decrease, [C, T1, C]),
	{M2, _} = timer:tc(?MODULE, decrease, [C, T2, C]),
	io:format("decrease from ~p for ~p times took ~p seconds.~n",[C, T1,
M1/1000000]),
	io:format("decrease from ~p for ~p times took ~p seconds.~n",[C, T2,
M2/1000000]).

% computational processes
decrease(0, 0, _Start) -> ok;
decrease(0, Times, Start) -> decrease(Start, Times - 1, Start);
decrease(N, Times, Start) -> decrease(N - 1, Times, Start).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


roberto$ erl
Erlang R13B04 (erts-5.7.5) [source] [smp:4:4] [rq:4] [async-threads:0]
[hipe] [kernel-poll:false]

Eshell V5.7.5  (abort with ^G)
1> c(lintest2).
{ok,lintest2}
2> lintest2:start().
decrease from 100000000 for 1 times took 1.546736 seconds.
decrease from 100000000 for 10 times took 8.472292 seconds.
ok
3>

r.


More information about the erlang-questions mailing list