Tail/Non tail recursion

Peter Lund peter@REDACTED
Thu Aug 28 18:37:37 CEST 2003


When I ran your code on my Win2K system several times I got
3 very different results...

1> c(square).
{ok,square}
2> square:run().
plain: 5027000
map: 2644000
comprehension: 2935000
ok
3> square:run().
plain: 8022000
map: 9023000
comprehension: 1302590
ok
4> square:run().
plain: 2433000
map: 3935000
comprehension: 2473000

Does this just show that W2K is crap? :)

Peter

> -module(square).
> -export([run/0,plain/1,map/1,comprehension/1]).
>
> run() ->
> 	List = lists:seq(1,1000000),
> 	timer:start(),
> 	lists:foreach(
> 	  fun(Fun) ->
> 			  {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].
>
>
>
> ------
>
> 2> c(square).
> {ok,square}
> 3> square:run().
> plain: 3155000
> map: 2003000
> comprehension: 1592000
> ok
> 4>
>
> (Win2K with R9B)
>
> Regards,
>
> Dominic.






More information about the erlang-questions mailing list