[erlang-questions] string to binary

Wes James <>
Wed Oct 19 16:36:16 CEST 2011


This is interesting. I run statistics() four times and on line 2 the
line is slower than line 4, but then after that it is always a little
faster.  What does reduction mean?  Number of internal operations?
Why would it be slower at first then faster the rest of the time?


Erlang R14B03 (erts-5.8.4) [source] [smp:4:4] [rq:4] [async-threads:0]
[hipe] [kernel-poll:false]

Eshell V5.8.4  (abort with ^G)
1> statistics(exact_reductions).
{361523,361523}
2> <<<<(list_to_integer(X, 16))>> || X <-
string:tokens("00:11:22:33:44:55", ":")>>.
<<0,17,34,51,68,85>>
3> statistics(exact_reductions).
{372349,10826}
4> list_to_binary([element(2, io_lib:fread("~16u", X)) || X <-
string:tokens("00:11:22:33:44:55", ":")]).
<<0,17,34,51,68,85>>
5> statistics(exact_reductions).
{381557,9208}
6>
6> statistics(exact_reductions).
{384225,2668}
7> <<<<(list_to_integer(X, 16))>> || X <-
string:tokens("00:11:22:33:44:55", ":")>>.
<<0,17,34,51,68,85>>
8> statistics(exact_reductions).
{390943,6718}
9> list_to_binary([element(2, io_lib:fread("~16u", X)) || X <-
string:tokens("00:11:22:33:44:55", ":")]).
<<0,17,34,51,68,85>>
10> statistics(exact_reductions).
{398753,7810}
11>
11> statistics(exact_reductions).
{401480,2727}
12> <<<<(list_to_integer(X, 16))>> || X <-
string:tokens("00:11:22:33:44:55", ":")>>.
<<0,17,34,51,68,85>>
13> statistics(exact_reductions).
{408436,6956}
14> list_to_binary([element(2, io_lib:fread("~16u", X)) || X <-
string:tokens("00:11:22:33:44:55", ":")]).
<<0,17,34,51,68,85>>
15> statistics(exact_reductions).
{416078,7642}
16>
16> statistics(exact_reductions).
{418788,2710}
17> <<<<(list_to_integer(X, 16))>> || X <-
string:tokens("00:11:22:33:44:55", ":")>>.
<<0,17,34,51,68,85>>
18> statistics(exact_reductions).
{425339,6551}
19> list_to_binary([element(2, io_lib:fread("~16u", X)) || X <-
string:tokens("00:11:22:33:44:55", ":")]).
<<0,17,34,51,68,85>>
20> statistics(exact_reductions).
{433142,7803}
21>
21>

Thanks,

-wes



More information about the erlang-questions mailing list