[erlang-questions] Performance question

Loïc Hoguin essen@REDACTED
Fri Nov 7 10:44:15 CET 2014


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.

On 11/07/2014 03:33 AM, Stu Bailey 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
>

-- 
Loïc Hoguin
http://ninenines.eu



More information about the erlang-questions mailing list