[erlang-questions] map over bitstring
Wed Oct 27 20:24:58 CEST 2010
How can I convert a bitstring that has only characters $1 and $0 into a binary.
<<0,1,0,0,1,0,0,1,0>> to << 2#0100100100 >> to << 292 >>
something similar to io_lib:fread("~2u", [$0,$1,$0,$0,$1,$0,$0,$1,$0])
but that works on bitstring instead of string.
On Mon, Oct 25, 2010 at 6:23 AM, Morten Krogh <mk@REDACTED> wrote:
> I followed your suggestion and compiled it to native code with erlc +native
> zip2.erl, which improves the runtime for
> both methods.
> The run times are, for a 100 MB binary, and the map function X -> X + 1 hard
> coded into the module and into the map method itself (which is not quite
> Not native:
> comprehension : 10 s
> my own bit syntax function : 14s
> comprehension: 3.7 s
> my own bit syntax function: 6 s
> So, yes native is an improvement!
> On 10/25/10 11:30 AM, Kostis Sagonas wrote:
>> Morten Krogh wrote:
>>> Sorry, in my recent reply to Tony I tested the comprehension on the
>>> constant ><<"B"">>.
>>> Putting everything in the module and comparing the same mapped function
>>> ,f , the result is that the comprehension is 30% faster than my matching
>>> based map function.
>> You may also want to try compiling the file to native code and report
>> whether or how this improves/changes the results.
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
More information about the erlang-questions