<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>