[erlang-questions] Fast binary reverse
Michael Uvarov
freeakk@REDACTED
Thu Oct 27 10:34:48 CEST 2011
Just don't use anonymous functions.
<code>
-module(bin).
-export([rev1/1, rev2/1]).
rev1(B) ->
S = size(B)*8,
<<X:S/integer-little>>=B,
<<X:S/integer-big>>.
rev2(B) ->
binary:list_to_bin(
lists:reverse(
binary:bin_to_list(B))).
</code>
29> timer:tc(bin,rev2,[<<"teribly">>]).
{5,<<"ylbiret">>}
30> timer:tc(bin,rev1,[<<"teribly">>]).
{11,<<"ylbiret">>}
--
Best regards,
Uvarov Michael
More information about the erlang-questions
mailing list