[erlang-questions] direct binary to integer conversion

Torben Hoffmann torben.lehoff@REDACTED
Sun Jan 1 22:26:12 CET 2012


In case you want to know if a function is  a bif...

xref:start(s).
xref:add_release(s,"c:/Program\ Files/erl5.7.4/",[{builtins,true}]).
{ok,Bifs} = xref:q(s,"B").
Bifs.

Change path to fit your release!

Cheers,
Torben

Sent from my iPhone

On 01/01/2012, at 22.03, Jesper Louis Andersen <jesper.louis.andersen@REDACTED> wrote:

> On 1/1/12 4:50 PM, Steve Davis wrote:
>> Actually this parse_integer ... it's around the same speed as
>> string:to_integer...
>> 
>> however:
>> 
>> list_to_integer(binary_to_list(<<"-12345">>))
>> 
>> is about 30% faster than both
>> 
> If the goal is speed, you should weigh in the price of constructing the intermediate list with the direct decoding approach. Given that Erlang uses a copying collector in the processes, the price of collecting a dead list is 0. So the only overhead is in the list creation and then afterwards consuming it. What may also come into effect here is that I bet list_to_integer/1 is a BIF - and as such they tend to be much faster by default.
> 
> -- 
> Jesper Louis Andersen
>  Erlang Solutions Ltd., Copenhagen, DK
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list