[erlang-questions] Performance question

Stu Bailey <>
Fri Nov 7 02:33:14 CET 2014


I found

binary:replace(BinChunk,<<"\n">>,<<>>,[global]).

*significantly *slower than

remove_pattern(BinChunk,<<>>,<<"\n">>).

with

remove_pattern(<<>>,Acc,_BinPat) ->
    Acc;
remove_pattern(Bin,Acc,BinPat)->
    <<Byte:1/binary,Rest/binary>> = Bin,
    case Byte == BinPat of
true -> remove_pattern(Rest,Acc,BinPat);
false -> remove_pattern(Rest,<<Acc/binary,Byte/binary>>,BinPat)
    end.

That was surprising to me.  The built-in binary:replace() was much much
slower for larger BinChunk  with lots of <<"\n">> sprinkled through.

Thoughts?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20141106/52fe385f/attachment.html>


More information about the erlang-questions mailing list