<html><head></head><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div id="yui_3_16_0_ym19_1_1478446594473_534227"><span id="yui_3_16_0_ym19_1_1478446594473_534228">Please write C nif containing function:<br><br></span></div><div style="font-family: Arial; font-size: 14px;" id="yui_3_16_0_ym19_1_1478446594473_534229">for(int i = 0 ;i< 100000000;++i)</div><div style="font-family: Arial; font-size: 14px;" id="yui_3_16_0_ym19_1_1478446594473_534231"><span style="white-space: pre-wrap;" id="yui_3_16_0_ym19_1_1478446594473_534232"> </span>{<span style="white-space: pre-wrap;" id="yui_3_16_0_ym19_1_1478446594473_534233"> </span></div><div style="font-family: Arial; font-size: 14px;" id="yui_3_16_0_ym19_1_1478446594473_534234"><span style="white-space: pre-wrap;" id="yui_3_16_0_ym19_1_1478446594473_534235"> </span>double b[5] = {1,2,3,4,5};</div><div style="font-family: Arial; font-size: 14px;" id="yui_3_16_0_ym19_1_1478446594473_534236"><span style="white-space: pre-wrap;" id="yui_3_16_0_ym19_1_1478446594473_534237"> </span>double s[5] = {6,7,8,9,10};</div><div style="font-family: Arial; font-size: 14px;" id="yui_3_16_0_ym19_1_1478446594473_534238"><span style="white-space: pre-wrap;" id="yui_3_16_0_ym19_1_1478446594473_534239"> </span>double o[5];</div><div style="font-family: Arial; font-size: 14px;" id="yui_3_16_0_ym19_1_1478446594473_534240"><span style="white-space: pre-wrap;" id="yui_3_16_0_ym19_1_1478446594473_534241"> </span>for(int i = 0; i < 5;++i)</div><div style="font-family: Arial; font-size: 14px;" id="yui_3_16_0_ym19_1_1478446594473_534242"><span style="white-space: pre-wrap;" id="yui_3_16_0_ym19_1_1478446594473_534243"> </span>{</div><div style="font-family: Arial; font-size: 14px;" id="yui_3_16_0_ym19_1_1478446594473_534244"><span style="white-space: pre-wrap;" id="yui_3_16_0_ym19_1_1478446594473_534245"> </span>o[i] = s[i] * b[i] * (1 - b[i]);</div><div style="font-family: Arial; font-size: 14px;" id="yui_3_16_0_ym19_1_1478446594473_534246"><span style="white-space: pre-wrap;" id="yui_3_16_0_ym19_1_1478446594473_534247"> </span>}</div><div style="font-family: Arial; font-size: 14px;" id="yui_3_16_0_ym19_1_1478446594473_534248"><br id="yui_3_16_0_ym19_1_1478446594473_534249"></div><div dir="ltr" style="font-family: Arial; font-size: 14px;" id="yui_3_16_0_ym19_1_1478446594473_534250"><span style="white-space: pre-wrap;" id="yui_3_16_0_ym19_1_1478446594473_534251"> </span>}.</div><div id="yui_3_16_0_ym19_1_1478446594473_534252"><span><br></span></div><div id="yui_3_16_0_ym19_1_1478446594473_534252"><span id="yui_3_16_0_ym19_1_1478446594473_534253"><br>change erlang code to:<br><br></span></div><div style="font-family: Arial; font-size: 14px;" id="yui_3_16_0_ym19_1_1478446594473_534057"><div id="yui_3_16_0_ym19_1_1478446594473_534058">test_sum_0(N) -><br> call_c_nif(N);</div></div><div style="font-family: Arial; font-size: 14px;" id="yui_3_16_0_ym19_1_1478446594473_534072"><br id="yui_3_16_0_ym19_1_1478446594473_534073"></div><div style="font-family: Arial; font-size: 14px;" id="yui_3_16_0_ym19_1_1478446594473_534074">Try test again.</div><div style="font-family: Arial; font-size: 14px;" id="yui_3_16_0_ym19_1_1478446594473_534084"><br></div> <div class="qtdSeparateBR"><br><br></div><div class="yahoo_quoted" style="display: block;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div dir="ltr"><font size="2" face="Arial"> On Friday, November 11, 2016 5:01 AM, 谈广云 <fw339tgy@126.com> wrote:<br></font></div> <br><br> <div class="y_msg_container"><div id="yiv0192038232"><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial;"><div>i campare the erlang's computing with c++ </div><div><br></div><div>erlang run 100000000 time the <span style="line-height:23.8px;">test_sum_0</span></div><div><br></div><div><div>test_sum_0(N) -></div><div> bp_eva_delta([1,2,3,4],[3,4,5,6],[]),</div><div> test_sum_0(N-1).</div><div><br></div><div><br></div><div>bp_eva_delta([],_,L) -></div><div><span class="yiv0192038232Apple-tab-span" style="white-space:pre;"> </span>lists:reverse(L);</div><div>bp_eva_delta([O|Output],[S|Sigma],L) -></div><div><span class="yiv0192038232Apple-tab-span" style="white-space:pre;"> </span>bp_eva_delta(Output,Sigma,[S * O * (1-O) |L]).<span class="yiv0192038232Apple-tab-span" style="white-space:pre;"> </span></div></div><div><br></div><div><br></div><div><br></div><div><br></div><div>c++ run the same time (<span style="line-height:23.8px;">100000000</span><span style="line-height:23.8px;"> </span><span style="line-height:1.7;">) the s</span>imilar fun ,</div><div><br></div><div><div>for(int i = 0 ;i< 100000000;++i)</div><div><span class="yiv0192038232Apple-tab-span" style="white-space:pre;"> </span>{<span class="yiv0192038232Apple-tab-span" style="white-space:pre;"> </span></div><div><span class="yiv0192038232Apple-tab-span" style="white-space:pre;"> </span>double b[5] = {1,2,3,4,5};</div><div><span class="yiv0192038232Apple-tab-span" style="white-space:pre;"> </span>double s[5] = {6,7,8,9,10};</div><div><span class="yiv0192038232Apple-tab-span" style="white-space:pre;"> </span>double o[5];</div><div><span class="yiv0192038232Apple-tab-span" style="white-space:pre;"> </span>for(int i = 0; i < 5;++i)</div><div><span class="yiv0192038232Apple-tab-span" style="white-space:pre;"> </span>{</div><div><span class="yiv0192038232Apple-tab-span" style="white-space:pre;"> </span>o[i] = s[i] * b[i] * (1 - b[i]);</div><div><span class="yiv0192038232Apple-tab-span" style="white-space:pre;"> </span>}</div><div><br></div><div><span class="yiv0192038232Apple-tab-span" style="white-space:pre;"> </span>}.</div></div><div><br></div><div>the erlang spend 29's , and c++ spend 2.78's.</div><div><br></div><div>why the erlang is so slower than c++?</div><div><br></div><div> Or I do not configure the right parameter?</div><div><br></div><div><br></div></div><br><br><span title="neteasefooter"><div> </div></span></div><br>_______________________________________________<br>erlang-questions mailing list<br><a ymailto="mailto:erlang-questions@erlang.org" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br><a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br><br><br></div> </div> </div> </div></div></body></html>