[erlang-questions] Erlang shows its slow face!

Edmond Begumisa ebegumisa@REDACTED
Sat Nov 13 15:36:07 CET 2010


Hello Gilberto,

Just an observation... When one approaches a language, programming  
environment or development tool, it's important to establish it's  
promises. Then judge it on how well it delivers on those promises. One  
shouldn't be surprised when it fails to deliver on something it has not  
promised. One should be suspicious if it promises everything.

For Erlang's case, I think the official FAQ sums it up pretty well...

"...The most common class of 'less suitable' problems is characterised by  
performance being a prime requirement and constant-factors having a large  
effect on performance..."

http://www.erlang.org/faq/introduction.html#id50247
http://www.erlang.org/faq/introduction.html#id49850

It would be odd if you found Erlang was slow at creating processes, or  
sending messages between processes, or the emulator kept crashing. That  
would indicate that it's failing to deliver on what it has promised.

Numerical algorithms? I don't think even C# makes any promises there. You  
should probably be looking for a math library like AMD's ACML with  
gcc/gfortran...

http://developer.amd.com/cpu/Libraries/acml/Pages/default.aspx

I'm no mathematician, but I experimented with ACML once when I was toying  
around with programming audio processor plugins for music production  
software. It made a world of difference (even though my plugins sucked).

If for some reason want to do high performance math from Erlang, you could  
look into writing a port, a linked-in driver or a NIF with a more  
appropriate set of tools then call that from Erlang.

- Edmond -


On Sat, 13 Nov 2010 18:37:08 +1100, Gilberto Carmenate García  
<co7eb@REDACTED> wrote:

> Hi all!
> I have been doing tests to Erlang I found this funny stuff that makes
> Pythagorean Triplets
>
> pythag(N) ->
>     [ {A,B,C} ||
>         A <- lists:seq(1,N),
>         B <- lists:seq(1,N),
>         C <- lists:seq(1,N),
>         A+B+C =< N,
>         A*A+B*B =:= C*C].
>
> I tested it agains an implementation I made in C# so, and takes 14
> secounds in my pc to do with 300 numbers in Erlang however in c# is just
> a secound, even when C# runs under VM too.
> So I did all possible ways for me to implement differents manners in
> Erlang looking for speed and all is the same, listed as  follows:
>
> So my question is, there are any way to do that even more fast, why 3
> nestes fors structs in C# are more effients that lists:foldr or
> lists:foreach in Erlang.
>
> %% FORMA 1
> py1(Max)->
>     L = lists:seq(1, Max),
>     lists:foldr(
>         fun(A, Acc3)->
>             lists:foldr(
>                 fun(B, Acc2)->
>                     lists:foldr(
>                         fun(C, Acc)->
>                             case ((A*A + B*B =:= C*C) andalso (A+B+C =<
> Max)) of
> 								true->
>                                     [{A,B,C}|Acc];
>                                 false->
>                                     Acc
>                             end
>                         end
>                     , Acc2, L)
>                 end
>             , Acc3, L)
>         end
>     , [], L).
>
>
>
> %% FORMA 2
> py2(Max)->
> 	fora(1, [], Max).
>
> fora(A, Acc, Max)->
> 	Acc1 = forb(A,1, Acc, Max),
> 	case A < Max of
>         true->
>             fora(A+1, Acc1, Max);
>         false->
>             Acc1
>     end.
>
> forb(A,B, Acc, Max)->
>     Acc1 = forc(A,B,1, Acc, Max),
>     case B < Max of
>         true->
>             forb(A,B+1, Acc1, Max);
>         false->
>             Acc1
>     end.
>
> forc(A,B,C, Acc, Max)->
>     Acc1 = case (A*A + B*B =:= C*C) andalso (A+B+C =< Max) of
>         true->
>             [{A,B,C}|Acc];
>         _->
>             Acc
>     end,
>     case C < Max of
>         true->
>             forc(A,B,C+1, Acc1, Max);
>         false->
>             Acc1
>     end.
>
> %% FORMA 3.
> py3(Max)->
> 	[{A,B,C} ||
> 		A <-lists:seq(1, Max),
> 		B <-lists:seq(1, Max),
> 		C <-lists:seq(1, Max),
> 		A*A + B*B =:= C*C,
> 		A+B+C =< Max].
>
>
> =======================================================================
> Este mensaje ha sido enviado mediante el servicio de correo electronico  
> que ofrece la Federacion de Radioaficionados de Cuba a sus miembros para  
> respaldar el cumplimiento de los objetivos de la organizacion y su  
> politica informativa. La persona que envia este correo asume el  
> compromiso de  usar el servicio a tales fines y cumplir con las  
> regulaciones establecidas.
>
>
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


More information about the erlang-questions mailing list