[erlang-questions] Performance question
Tyler Margison
kolorahl@REDACTED
Fri Nov 7 04:41:03 CET 2014
I'm not sure if this would affect performance or not, but I believe
binary:replace looks at variable-sized patterns whereas your remove_pattern
function only work for one-byte patterns. What if the pattern is larger
than 1-byte in length? It definitely works for <<"\n">> but I don't think
it would work for <<"\r\n">>. 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.
On Thu, Nov 6, 2014 at 5:33 PM, Stu Bailey <stu.bailey@REDACTED> wrote:
> 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?
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20141106/2b69f294/attachment.htm>
More information about the erlang-questions
mailing list