<div dir="ltr">FYI,  if you want to try to replicate it, I was processing ~80 chunks of binary where each chunk was about ~250,000,000 bytes.  I think you'll see the difference on just one chunk.  I happen to running on a 8-core MacBook Pro with 16GB Ram and therefore spawned a process per chunk to grab all the resources on all the cores.   With the hand written function, it worked like a charm...yay Erlang! :-)  I love seeing a few lines of code effectively use all processing power available.  Heats the machine up quite a bit too. :-)<div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 7, 2014 at 9:22 AM, 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'm not planning to spend a lot of time on this right now, but the binary:replace(...) was chewing a tremendous amount of system time CPU load (and actually never finished before I got frustrated and killed it) and my function was reporting the CPU load as 99% user time (not system time) and finished in a reasonable time.   I assume the high system time usage for binary:replace(..)  is because binary:replace(...) is doing something manic with system calls for memory management or something?<div><div class="h5"><div><div><br><div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 7, 2014 at 1:44 AM, Loïc Hoguin <span dir="ltr"><<a href="mailto:essen@ninenines.eu" target="_blank">essen@ninenines.eu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">binary:split and binary:replace, unlike other functions of the binary module, are normal Erlang functions. They also process a list of options before doing the actual work, so there's an obvious overhead compared to not doing that. In addition as has been pointed out, your code is more specialized so that helps too.<span><br>
<br>
On 11/07/2014 03:33 AM, Stu Bailey wrote:<br>
</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>
I found<br>
<br>
binary:replace(BinChunk,<<"\n"<u></u>>>,<<>>,[global]).<br>
<br></span>
/significantly /slower than<span><br>
<br>
remove_pattern(BinChunk,<<>>,<<u></u><"\n">>).<br>
<br>
with<br>
<br>
remove_pattern(<<>>,Acc,_<u></u>BinPat) -><br>
     Acc;<br>
remove_pattern(Bin,Acc,BinPat)<u></u>-><br>
     <<Byte:1/binary,Rest/binary>> = Bin,<br>
     case Byte == BinPat of<br>
true -> remove_pattern(Rest,Acc,<u></u>BinPat);<br>
false -> remove_pattern(Rest,<<Acc/<u></u>binary,Byte/binary>>,BinPat)<br>
     end.<br>
<br>
That was surprising to me.  The built-in binary:replace() was much much<br>
slower for larger BinChunk with lots of <<"\n">> sprinkled through.<br>
<br>
Thoughts?<br>
<br>
<br></span><span>
______________________________<u></u>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<u></u>listinfo/erlang-questions</a><br>
<br>
</span></blockquote><span><font color="#888888">
<br>
-- <br>
Loïc Hoguin<br>
<a href="http://ninenines.eu" target="_blank">http://ninenines.eu</a><br>
</font></span></blockquote></div><br></div></div></div></div></div></div></div>
</blockquote></div><br></div></div>