<div dir="ltr">Hi!<div><br></div><div>I perform the same test on my machine:</div><div><br></div><div><b>For Ruby:</b></div><div><br></div><div><b># irb</b></div><div><br></div><div><font size="1">require 'benchmark'<br>
</font></div><div><font size="1"><br></font></div><div><font size="1">n = 50000<br></font></div><div><font size="1"><br></font></div><div><div><font size="1">text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</font></div>
<div><font size="1">=> "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</font></div>
</div><div><font size="1"><br></font></div><div><font size="1">puts Benchmark.measure { n.times { text.split /\s+/ } }</font><br></div><div><br></div><div>3.850000 0.010000 3.860000 ( <b>3.955543</b>)<br></div><div><br>
</div><div><b>For Erlang:</b></div><div><br></div><div><b># erl</b></div><div><br></div><div><font size="1">N = lists:seq(1, 50000).</font></div><div><font size="1"><br></font></div><div><font size="1">Text = <<"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.">>.<br>
</font></div><div><font size="1"><br></font></div><div><font size="1">F = fun() -> {ok, Pattern} = re:compile("\\s+"), re:split(Text, Pattern), ok end.<br></font></div><div><font size="1"><br></font></div><div>
<font size="1">F1 = fun() -> [F() || _ <- N] end.</font></div><div><font size="1"><br></font></div><div><font size="1">{T, _} = timer:tc(F1).<br></font></div><div><font size="1"><br></font></div><div><font size="1">T / 1000000.</font></div>
<div><br></div><div><b>13.7556<br></b></div><div><br></div><div><b># erl</b></div><div><br></div><div><div><font size="1">N = lists:seq(1, 50000).</font></div><div><font size="1"><br></font></div><div><font size="1">Text = <<"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.">>.<br>
</font></div></div><div><font size="1"><br></font></div><div><span style="font-size:x-small">{ok, Pattern} = re:compile("\\s+").</span><br></div><div><font size="1"><br></font></div><div><div><font size="1">F = fun() -> re:split(Text, Pattern), ok end.<br>
</font></div><div><font size="1"><br></font></div><div><font size="1">F1 = fun() -> [F() || _ <- N] end.</font></div><div><font size="1"><br></font></div><div><font size="1">{T, _} = timer:tc(F1).<br></font></div><div>
<font size="1"><br></font></div><div><font size="1">T / 1000000.</font></div></div><div><font size="1"><br></font></div><div><b>12.8033<br></b></div><div><br></div><div><b># erl -smp disable</b></div><div><br></div><div><div>
<font size="1">N = lists:seq(1, 50000).</font></div><div><font size="1"><br></font></div><div><font size="1">Text = <<"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.">>.<br>
</font></div><div><font size="1"><br></font></div><div><font size="1">F = fun() -> {ok, Pattern} = re:compile("\\s+"), re:split(Text, Pattern), ok end.<br></font></div><div><font size="1"><br></font></div><div>
<font size="1">F1 = fun() -> [F() || _ <- N] end.</font></div><div><font size="1"><br></font></div><div><font size="1">{T, _} = timer:tc(F1).<br></font></div><div><font size="1"><br></font></div><div><font size="1">T / 1000000.</font></div>
</div><div><br></div><div><b>8.927621<br></b></div><div><br></div><div><b># erl -smp disable</b></div><div><br></div><div><div><div><font size="1">N = lists:seq(1, 50000).</font></div><div><font size="1"><br></font></div>
<div><font size="1">Text = <<"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.">>.<br>
</font></div></div><div><font size="1"><br></font></div><div><span style="font-size:x-small">{ok, Pattern} = re:compile("\\s+").</span><br></div><div><font size="1"><br></font></div><div><div><font size="1">F = fun() -> re:split(Text, Pattern), ok end.<br>
</font></div><div><font size="1"><br></font></div><div><font size="1">F1 = fun() -> [F() || _ <- N] end.</font></div><div><font size="1"><br></font></div><div><font size="1">{T, _} = timer:tc(F1).</font></div><div><font size="1"><br>
</font></div><div><font size="1">T / 1000000.</font></div></div></div><div><br></div><div>8.657157<br></div><div><br></div><div><br></div><div>The ruby and erlang utilize my cpu for 100%. As you can see, I make some tricks, it make erlang a little bit faster, but it still not enough.</div>
<div><br></div><div>If you need process lagre amount of text, you should use erlang:spawn for each text object, it will be very fast.</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/12/18 akonsu <span dir="ltr"><<a href="mailto:akonsu@gmail.com" target="_blank">akonsu@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I have two benchmarks that perform a simple text split on a regular expression. One is in Ruby and another is in Erlang. The Erlang version is 6 times slower on my machine for some reason. I have read all documentation I could find on how to use binaries in Erlang, but I cannot make it faster. I am looking for help.<div>
<br></div><div><br><div><br></div><div>Here is the code:</div><div><br></div><div>Ruby:</div><div><br></div><div><div>require 'benchmark'</div><div><br></div><div>n = 50000</div><div>text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</div>
<div><br></div><div>puts Benchmark.measure {</div><div> n.times { text.split /\s+/ }</div><div>}</div></div><div><br></div><div><br></div><div>Erlang:</div><div><br></div><div><div>text() -></div><div> <<"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.">>.</div>
</div><div><br></div><div><div>times(0, _) -></div><div> ok;</div><div>times(N, F) -></div><div> F(),</div><div> times(N - 1, F).</div><div><br></div><div>measure(N) -></div><div> {ok, Pattern} = re:compile("\\s+"),</div>
<div> B = text(),<br></div><div> F = fun() -> re:split(B, Pattern) end,</div><div> {T, ok} = timer:tc(?MODULE, times, [N, F]),<br></div><div> T / 1000000.</div></div><div><br></div><div>Ruby outputs</div><div>
<br></div><div> 3.180000 0.000000 3.180000 ( 3.182452)<br></div><div><br></div><div>Erlang outputs</div><div><br></div><div><div>Erlang R16B03 (erts-5.10.4) [source] [smp:2:2] [async-threads:10] [hipe] [kernel-poll:false]</div>
<div><br></div><div>Eshell V5.10.4 (abort with ^G)</div><div>1> test:measure(50000).</div><div>18.261952</div></div><div><br></div></div></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a 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></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Петровский Александр / Alexander Petrovsky,<br><br>Skype: askjuise<br>Jabber: <a href="mailto:juise@jabber.ru" target="_blank">juise@jabber.ru</a><br>
<div>Phone: +7 914 8 820 815 (irkutsk)<div><br></div></div></div>
</div>