[erlang-questions] Efficiency of splitting binaries
Wed Oct 24 15:55:21 CEST 2007
Richard Andrews wrote:
> I'm looking for advice on efficiently splitting a binary into smaller chunks.
> I currently use iolist_size() to check the size of the input binary then
> recursively break off a chunk from the front with something like, eg.
Why are you using iolist_size()? Is it possiblethat your input is not a
> << ChunkData:30/binary-unit:8, RestData/binary >> = Data
This should be efficient you are creating sub-binaries for both
ChunkData and RestData so the cost should be independent of their
> ... then use RestData as input to the next cycle.
> Is this sensible? Are there more efficient approaches?
> What effect does the binary-unit specifier have on performance? eg.
As long as Size*Unit remains the same this should not affect the runtime
at all, but note that ChunkData:240/binary really means
More information about the erlang-questions