[erlang-questions] Erlang/YAWS vs Free Pascal/Xitami
Richard A. O'Keefe
ok@REDACTED
Wed Mar 26 04:15:37 CET 2008
On 25 Mar 2008, at 8:58 pm, Jilani Khaldi wrote:
> Which is better for my web application?
> http://www.dotpas.org/cgi-bin/articles/a01
First, the Erlang code can be substantially simplified to
var(Xs) -> % function name copied from S/S+/R
N = length(Xs),
Mean = lists:sum(Xs)/N,
Centred_Xs = [X - Mean || X <- Xs],
lists:sum([X*X || X <- Centred_Xs])/(N-1).
sd(Xs) -> % function name copied from S/S+/R
sqrt(var(Xs)).
out(A) ->
Xs = lists:seq(1, 1000),
SD = sd(Xs),
T = io_lib:format("Std Dev: ~.6f ", [SD]),
{html, T}.
Second, if you were using Apache, it would make sense to use
-------------- next part --------------
A non-text attachment was scrubbed...
Name: inherit.gif
Type: image/gif
Size: 57 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080326/eb7ab56d/attachment.gif>
-------------- next part --------------
org.apache.commons.math.stat.descriptive.moment.Variance
to do the variance calculation, and it is clearly "better" to have
code just sitting there waiting for you to use it than to have to write
it and test it yourself. (Of course, ideally Erlang would have a
'stats:' module with at least mean/1, var/1, and sd/1 in it.)
But third is most important: what do you mean by "better"?
- Better = it takes you less time to write it?
That depends in part on how well you know the language and its
libraries.
- Better = it is more reliable once written?
I'd say Erlang every time; on the other hand these days there are web
servers written in Haskell, so you might want the security of strong
(polymorphic) typing as well as the safety of assignment-freedom.
- Better = runs in less time on your machine?
First get it working, then measure. Once it is fast enough, stop
worrying.
"Fast enough" depends on workload, of course.
- Better = runs in less memory on your machine?
For an application that only needs one process, Pascal is likely to
do
better than Erlang here. For an application that needs many
processes,
Erlang is likely to do better than Pascal.
More information about the erlang-questions
mailing list