[erlang-questions] binary_to_integer/1 and binary_to_float/1 and friends

Bob Ippolito bob@REDACTED
Mon Apr 30 20:35:07 CEST 2012


On Mon, Apr 30, 2012 at 11:18 AM, Max Lapshin <max.lapshin@REDACTED> wrote:

> On Mon, Apr 30, 2012 at 10:13 PM, Bob Ippolito <bob@REDACTED> wrote:
> >
> > I suppose you could implement it in pure erlang without creating any
> > intermediate lists, maybe it's even fast with HIPE. Floats are likely
> > another story.
> >
>
> It also creates lots of intermediate objects and we both know how
> "fast" erlang arithmetic is.
>
> Floats can be parsed in the same way.
>
> In fact parsing in C can be done in the way, you have described. And
> it is many times faster, according to my benchmarks, done while
> working with CSV.
>
> You should remember that intermediate objects lead to useless GC.
>

Well, when numbers are small enough (60 or 28 bits depending on if it's
full word 64-bit or not, see ./erts/emulator/beam/erl_term.h) they are
stored as immediate fixnums, and the match context shouldn't have much
overhead either. I have no doubt that it's significantly slower than good C
code, but maybe it's better than the combination of binary_to_list/1 and
list_to_integer/1 BIFs.

-bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120430/6f90646c/attachment.htm>


More information about the erlang-questions mailing list