[erlang-questions] Why erlang's computing performance is enormously less than c++

Tony Rogvall tony@REDACTED
Fri Nov 11 14:10:10 CET 2016


The original program is looping over [1,2,3,4] when it should loop over [1,2,3,4,5] as
in the C program. After fixing that and also making sure the program is using floating point
numbers and adding a variable that calculate a result, then the difference is  ( on my mac )

Erlang: 57s
C: 3.7s

That is 15 times slower which is not that bad considering :-)
But when adding a -O3 flag to the C code compilation that ratio will increases to 110 times slower.
Just tossing in a -native flag did not lead to a any significant change but…
The when using the still forgotten loop unrolling directives, inline sizes and friends.
I used this ( WARNING! not to be used in production code yet, I guess? )

-compile(native).
-compile(inline).
-compile({inline_size,1000}).
-compile({inline_effort,2000}).
-compile({inline_unroll,6}).

Erlang: 4.3s

Which is nearly the same as unoptimized C code and
just 8 times slower than -O3 optimized C code.
and that is just amazing!

/Tony

> On 11 nov 2016, at 11:13, Richard Carlsson <carlsson.richard@REDACTED> wrote:
> 
> You are comparing a native-compiled C++ program that works on small arrays of raw numbers with an interpreted Erlang program that traverses linked lists of tagged numbers. The only surprise is that the difference is _only_ a factor 10. (And if the C code was using integers instead of double precision floats, it would be even faster.)
> 
> 
>         /Richard
> 
> 2016-11-11 8:26 GMT+01:00 谈广云 <fw339tgy@REDACTED>:
> i campare the erlang's computing with c++
> 
> erlang run 100000000 time the test_sum_0
> 
> test_sum_0(N) ->
>   bp_eva_delta([1,2,3,4],[3,4,5,6],[]),
>   test_sum_0(N-1).
> 
> 
> bp_eva_delta([],_,L) ->
> 	lists:reverse(L);
> bp_eva_delta([O|Output],[S|Sigma],L) ->
> 	bp_eva_delta(Output,Sigma,[S * O * (1-O) |L]).
> 
> 
> 
> 
> c++ run the same time (100000000 ) the similar fun ,
> 
> for(int i = 0 ;i< 100000000;++i)
> 	{
> 		double b[5] = {1,2,3,4,5};
> 		double s[5] = {6,7,8,9,10};
> 		double o[5];
> 		for(int i = 0; i < 5;++i)
> 		{
> 			o[i] = s[i] * b[i] * (1 - b[i]);
> 		}
> 
> 	}.
> 
> the erlang spend 29's , and c++ spend 2.78's.
> 
> why the erlang is so slower than c++?
> 
>  Or I do not configure  the right parameter?
> 
> 
> 
> 
> 
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
> 
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20161111/58939f15/attachment.bin>


More information about the erlang-questions mailing list