[erlang-questions] map over bitstring
Robert Virding
robert.virding@REDACTED
Thu Oct 28 23:23:24 CEST 2010
Seeing binaries contain bytes getting the binary << 292 >> is impossible. You have to put it in more that 8 bits.
Robert
----- "rgowka1" <rgowka1@REDACTED> wrote:
> Hi -
>
> 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.
>
> thanks.
>
> On Mon, Oct 25, 2010 at 6:23 AM, Morten Krogh <mk@REDACTED>
> wrote:
> > Kostis,
> >
> > 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
> > realistic):
> >
> > Not native:
> >
> > comprehension : 10 s
> > my own bit syntax function : 14s
> >
> > native:
> >
> > comprehension: 3.7 s
> > my own bit syntax function: 6 s
> >
> > So, yes native is an improvement!
> >
> > Morten.
> >
> >
> >
> > 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.
> >>
> >> Morten,
> >>
> >> You may also want to try compiling the file to native code and
> report
> >> whether or how this improves/changes the results.
> >>
> >> Cheers,
> >> Kostis
> >
> >
> > ________________________________________________________________
> > erlang-questions (at) erlang.org mailing list.
> > See http://www.erlang.org/faq.html
> > To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
> >
> >
>
> ________________________________________________________________
> 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
mailing list