[erlang-bugs] Re: UTF8 string handling in different erlang:*** functions
Tue Mar 29 17:34:29 CEST 2011
Paulo Sérgio Almeida wrote:
> On 3/29/11 3:10 PM, Nico Kruber wrote:
>>> 1000000 iterations of "erlang:term_to_binary/1" took 0.02946s:
>>> 1000000 iterations of "unicode:characters_to_binary/1" took 0.667519s:
>> -> looks like I should chose erlang:term_to_binary/1 since at least
>> on my
>> machine is is around twice as fast.
> It's not twice but 20 times as fast. Amazing. Even though it should be
> slower, this slower is surprising.
I have trouble reproducing these numbers, both the 2 and the 20.
With the program at the end of this mail, on an x86_64, I get:
Eshell V5.8.3 (abort with ^G)
2> timer:tc(t, t2b, ).
3> timer:tc(t, c2b, ).
which makes the term_to_binary version about 4 times as fast on this
machine. On a 32-bit machine the difference is about 6 - 6.5 times.
-define(S, "some medium sized string here").
lists:foreach(fun (_) -> erlang:term_to_binary(?S) end, lists:seq(1,N)).
lists:foreach(fun (_) -> unicode:characters_to_binary(?S) end,
More information about the erlang-bugs