<div dir="ltr">No, really I compile my code to beam file and then run from shell.<br><div class="gmail_extra"><br><br><div class="gmail_quote">2013/12/22 Peer Stritzinger <span dir="ltr"><<a href="mailto:peerst@gmail.com" target="_blank">peerst@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>
<div>
<p>It looks like you run these benchmarks in the shell.</p>
<p><br></p>
<p>Code run in the shell is interpreted in Erlang and much slower than compiled code.</p>
<p><br></p>
<p>Besides looping with a comprehension and building a large list might also more overhead than necessary.</p><div><div class="h5">
<p><br></p>
<p>On 2013-12-22 12:29:43 +0000, Alexander Petrovsky said:</p>
<p><br></p>
<p>Hi!</p>
<p><br></p>
<p>I perform the same test on my machine:</p>
<p><br></p>
<p>For Ruby:</p>
<p><br></p>
<p># irb</p>
<p><br></p>
<p>require 'benchmark'</p>
<p><br></p>
<p>n = 50000</p>
<p><br></p>
<p>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."</p>
<p>=> "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."</p>
<p><br></p>
<p>puts Benchmark.measure { n.times { text.split /\s+/ } }</p>
<p><br></p>
<p>3.850000 0.010000 3.860000 ( 3.955543)</p>
<p><br></p>
<p>For Erlang:</p>
<p><br></p>
<p># erl</p>
<p><br></p>
<p>N = lists:seq(1, 50000).</p>
<p><br></p>
<p>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.">>.</p>
<p><br></p>
<p>F = fun() -> {ok, Pattern} = re:compile("\\s+"), re:split(Text, Pattern), ok end.</p>
<p><br></p>
<p>F1 = fun() -> [F() || _ <- N] end.</p>
<p><br></p>
<p>{T, _} = timer:tc(F1).</p>
<p><br></p>
<p>T / 1000000.</p>
<p><br></p>
<p>13.7556</p>
<p><br></p>
<p># erl</p>
<p><br></p>
<p>N = lists:seq(1, 50000).</p>
<p><br></p>
<p>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.">>.</p>
<p><br></p>
<p>{ok, Pattern} = re:compile("\\s+").</p>
<p><br></p>
<p>F = fun() -> re:split(Text, Pattern), ok end.</p>
<p><br></p>
<p>F1 = fun() -> [F() || _ <- N] end.</p>
<p><br></p>
<p>{T, _} = timer:tc(F1).</p>
<p><br></p>
<p>T / 1000000.</p>
<p><br></p>
<p>12.8033</p>
<p><br></p>
<p># erl -smp disable</p>
<p><br></p>
<p>N = lists:seq(1, 50000).</p>
<p><br></p>
<p>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.">>.</p>
<p><br></p>
<p>F = fun() -> {ok, Pattern} = re:compile("\\s+"), re:split(Text, Pattern), ok end.</p>
<p><br></p>
<p>F1 = fun() -> [F() || _ <- N] end.</p>
<p><br></p>
<p>{T, _} = timer:tc(F1).</p>
<p><br></p>
<p>T / 1000000.</p>
<p><br></p>
<p>8.927621</p>
<p><br></p>
<p># erl -smp disable</p>
<p><br></p>
<p>N = lists:seq(1, 50000).</p>
<p><br></p>
<p>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.">>.</p>
<p><br></p>
<p>{ok, Pattern} = re:compile("\\s+").</p>
<p><br></p>
<p>F = fun() -> re:split(Text, Pattern), ok end.</p>
<p><br></p>
<p>F1 = fun() -> [F() || _ <- N] end.</p>
<p><br></p>
<p>{T, _} = timer:tc(F1).</p>
<p><br></p>
<p>T / 1000000.</p>
<p><br></p>
<p>8.657157</p>
<p><br></p>
<p><br></p>
<p>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.</p>
<p><br></p>
<p>If you need process lagre amount of text, you should use erlang:spawn for each text object, it will be very fast.</p>
<p><br></p>
<p><br></p>
<p><br></p>
<p>2013/12/18 akonsu <span><<a href="mailto:akonsu@gmail.com" target="_blank"><span>akonsu@gmail.com</span></a>></span></p>
<p>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.</p>
<p><br></p>
<p><br></p>
<p><br></p>
<p>Here is the code:</p>
<p><br></p>
<p>Ruby:</p>
<p><br></p>
<p>require 'benchmark'</p>
<p><br></p>
<p>n = 50000</p>
<p>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."</p>
<p><br></p>
<p>puts Benchmark.measure {</p>
<p> n.times { text.split /\s+/ }</p>
<p>}</p>
<p><br></p>
<p><br></p>
<p>Erlang:</p>
<p><br></p>
<p>text() -></p>
<p> <<"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.">>.</p>
<p><br></p>
<p>times(0, _) -></p>
<p> ok;</p>
<p>times(N, F) -></p>
<p> F(),</p>
<p> times(N - 1, F).</p>
<p><br></p>
<p>measure(N) -></p>
<p> {ok, Pattern} = re:compile("\\s+"),</p>
<p> B = text(),</p>
<p> F = fun() -> re:split(B, Pattern) end,</p>
<p> {T, ok} = timer:tc(?MODULE, times, [N, F]),</p>
<p> T / 1000000.</p>
<p><br></p>
<p>Ruby outputs</p>
<p><br></p>
<p> 3.180000 0.000000 3.180000 ( 3.182452)</p>
<p><br></p>
<p>Erlang outputs</p>
<p><br></p>
<p>Erlang R16B03 (erts-5.10.4) [source] [smp:2:2] [async-threads:10] [hipe] [kernel-poll:false]</p>
<p><br></p>
<p>Eshell V5.10.4 (abort with ^G)</p>
<p>1> test:measure(50000).</p>
<p>18.261952</p>
<p><br></p>
<p><br></p>
<p>_______________________________________________</p>
<p>erlang-questions mailing list</p>
<p><span><a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a></span></p>
<p><span><a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a></span></p>
<p><br></p>
<p><br></p>
<p><br></p>
<p><br></p>
<p>--<span> </span></p>
<p>Петровский Александр / Alexander Petrovsky,</p>
<p><br></p>
<p>Skype: askjuise</p>
<p>Jabber: <a href="mailto:juise@jabber.ru" target="_blank"><span>juise@jabber.ru</span></a></p>
<p>Phone: +7 914 8 820 815 (irkutsk)</p>
<p><br></p>
</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></div>