<div dir="ltr">I'm not sure if this would affect performance or not, but I believe <font face="courier new, monospace">binary:replace</font> looks at variable-sized patterns whereas your <font face="courier new, monospace">remove_pattern</font> function only work for one-byte patterns. What if the pattern is larger than 1-byte in length? It definitely works for <font face="courier new, monospace"><<"\n">></font> but I don't think it would work for <font face="courier new, monospace"><<"\r\n">></font>. Perhaps there is a performance degradation when calculating pattern length? Again, I'm not sure if that's part of the performance problem, but the two functions you propose are not quite synonymous.</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 6, 2014 at 5:33 PM, Stu Bailey <span dir="ltr"><<a href="mailto:stu.bailey@gmail.com" target="_blank">stu.bailey@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I found <div><br></div><div><font face="courier new, monospace">binary:replace(BinChunk,<<"\n">>,<<>>,[global]).</font><br></div><div><font face="courier new, monospace"><br></font></div><div><font face="arial, helvetica, sans-serif"><i>significantly </i>slower than </font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><span style="font-family:'courier new',monospace">remove_pattern(BinChunk,<<>>,<<"\n">>).</span><font face="arial, helvetica, sans-serif"><br></font></div><div><span style="font-family:'courier new',monospace"><br></span></div><div><font face="arial, helvetica, sans-serif">with</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><div><font face="courier new, monospace">remove_pattern(<<>>,Acc,_BinPat) -></font></div><div><font face="courier new, monospace"> Acc;</font></div><div><font face="courier new, monospace">remove_pattern(Bin,Acc,BinPat)-></font></div><div><font face="courier new, monospace"> <<Byte:1/binary,Rest/binary>> = Bin,</font></div><div><font face="courier new, monospace"> case Byte == BinPat of</font></div><div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>true -> remove_pattern(Rest,Acc,BinPat);</font></div><div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>false -> remove_pattern(Rest,<<Acc/binary,Byte/binary>>,BinPat)</font></div><div><font face="courier new, monospace"> end.</font></div></div><div><font face="courier new, monospace"><br></font></div><div><font face="arial, helvetica, sans-serif">That was surprising to me. The built-in </font><font face="courier new, monospace">binary:replace() </font><font face="arial, helvetica, sans-serif">was much much slower for larger </font><font face="courier new, monospace">BinChunk</font><font face="arial, helvetica, sans-serif"> with lots of </font><font face="courier new, monospace"><<"\n">> </font><font face="arial, helvetica, sans-serif">sprinkled through.</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Thoughts?</font></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></div>