[erlang-questions] direct binary to integer conversion

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Sun Jan 1 22:03:58 CET 2012


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




More information about the erlang-questions mailing list