[erlang-questions] Erlang/YAWS vs Free Pascal/Xitami

Ulf Wiger ulf@REDACTED
Tue Mar 25 10:13:02 CET 2008


It would seem as if the cost of the chosen math operations is not
that crucial for overall performance.

The Erlang code is obviously much more compact.
It can be made more compact by noting that:

  somma(L) -> somma(L,0).
  somma([], Acc) -> Acc;
  somma([H|T], Acc) -> somma(T, Acc+H).

is equivalent to lists:sum(L)

  quadrati([H|T]) -> [(H*H)|quadrati(T)];
  quadrati([]) -> [].

is equivalent to [X*X || X <- L]

  diff([H|T], K) -> [(H-K)|diff(T,K)];
  diff([], _) -> [].

is equivalent to [X-K || X <- L]

...which gives us:

var_dev(V) ->
  Len = length(V),
  Media = lists:sum(V) / Len,
  D = [X-Media || X <- V],
  Q = [X*X || X <-D],
  S = lists:sum(Q),
  Var = S / Len,
  Dev = math:sqrt(Var),
  {Media, D, Q, S, Var, Dev}.

out(A) ->
Z=lists:seq(1,1000),
{Media, D, Q, S, Var, Dev} = var_dev(Z),
T=io_lib:format("Std Dev: ~.6f ", [Dev]),
{html, T}.



BR,
Ulf W


2008/3/25, Jilani Khaldi <jilani@REDACTED>:
> Which is better for my web application?
>  http://www.dotpas.org/cgi-bin/articles/a01
>
>
>  --
>  ***
>  Jilani KHALDI
>  http://www.dotpas.org
>  _______________________________________________
>  erlang-questions mailing list
>  erlang-questions@REDACTED
>  http://www.erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list