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

Raimo Niskanen raimo+erlang-questions@REDACTED
Fri Nov 11 11:10:07 CET 2016


On Fri, Nov 11, 2016 at 03:26:30PM +0800, 谈广云 wrote:
> 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++?
> 

You are comparing apples with pears.

For starters; your Erlang code probably spends most of it time allocing new
memory, garbage collecting and freeing memory, while your C++ code just
reads and writes from the same stack memory locations.

Both examples produce nothing but in different ways.
This is a very syntethic and unjust comparision.

> 
>  Or I do not configure  the right parameter?

What are you trying to measure?


-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list