binaries vs lists

Bengt Kleberg Bengt.Kleberg@REDACTED
Tue Nov 11 14:24:28 CET 2003

Serge Aleynikov wrote:
> Hi!
> I was wonderting if someone could contribute a thought to the following 
> question regarding efficiency.

does it have to be efficient? have you found this to be a bottle neck?

> I have an Erlang TCP client that processes a binary stream which needs 
> to be post-processed by removing escaped bytes.  Let's say, that byte 
> 16$FF is escaped as <<16#FE, 16$01>>, and the 16#FF value is used as a 
> message separator.  The variable hex messages are within 512 bytes each.

if i understood the 512 bytes statement correctly, it is ok to build the 
list on the stack, thus avoiding lists:reverse/1 in solution 1.

> What would be faster for Erlang:
> 1. Declare a socket to return a *list* of bytes, and do something like:
> 2. Alternatively, declare a socket to return *binaries*, and do:
> Intuitively I think that the binary approach should work faster, but I 
> want to make sure that concat_binary is not expensive to do for every 
> byte in a stream.

have you tried to measure the performance of both? i do not know about 
your intuition, but mine is very unreliable.


More information about the erlang-questions mailing list