[erlang-questions] map over bitstring

Morten Krogh <>
Fri Oct 22 13:31:19 CEST 2010


Yes, Tony.

Now binary comprehension is 16 faster than the matching function.

So the slow part is that it has to get back to the shell and get the 
<<"b">> (which is silly in this case because it is constant).


cheers,

Morten.


On 10/22/10 1:16 PM, Tony Rogvall wrote:
>
> On 22 okt 2010, at 11.25, Morten Krogh wrote:
>
>>
>> To my enormous surprise, this program is about 7 times faster than 
>> the binary comprehension.
>>
>>
>> 18>  A = binary:copy(<<"a">>, 10000000).
>>
>> 10 MB, that is.
>>
>>
>> 19> T1 = now(), B = << <<"b">> || <<Y>> <= A>>, T2 = now(), 
>> timer:now_diff(T2,T1).
>> 68860012
>>
> Interpreted code !!!  Put this code in  a module and compile it, then 
> try again.
>
>> 22> f(T1), f(T2), f(B).
>> ok
>> 23> T1 = now(), B = zip2:map(fun(X) -> 98 end, A), T2 = now(), 
>> timer:now_diff(T2,T1).
>> 9284114
>>
> I guess zip2 is compiled.
>
>> (zip2 is my module name for this test)
>>
>>
>> What is going on?
>>
> There is a big speed difference between interpreted code and compiled 
> code.
>
> /Tony
>
> /"Have run Make so many times I dunno what's installed anymore"/
>



More information about the erlang-questions mailing list