Tail/Non tail recursion

Martin Sandiford ms@REDACTED
Fri Aug 29 00:59:41 CEST 2003


Hi Dominic,

My numbers seem to be more stable if I run erlang:garbage_collect()
before the timer:tc(...).

Linux, PIII 1GHz, R9C:

(a@REDACTED)6> perf:run().
plain: 1177035
map: 1640737
comprehension: 721675
ok


On Thu, 28 Aug 2003, WILLIAMS Dominic wrote:

> -module(square).
> -export([run/0,plain/1,map/1,comprehension/1]).
> 
> run() ->
> 	List = lists:seq(1,1000000),
> 	timer:start(),
> 	lists:foreach(
> 	  fun(Fun) ->
                          erlang:garbage_collect(), %% <- Inserted
> 			  {Time,_} = timer:tc(?MODULE,Fun,[List]),
> 			  io:fwrite("~w: ~w~n",[Fun,Time])
> 	  end,
> 	  [plain,map,comprehension]).
> 
> plain([H|T]) -> [H*H|plain(T)];
> plain([]) -> [].
> 
> map(Numbers) ->
> 	lists:map(fun(X)->X*X end,Numbers).
> 
> comprehension(Numbers)->
> 	[X*X||X<-Numbers].



More information about the erlang-questions mailing list