[erlang-questions] map over bitstring

Morten Krogh <>
Fri Oct 22 13:49:28 CEST 2010


Sorry, in my recent reply to Tony I tested the comprehension on the 
constant ><<"B"">>.


Putting everything in the module and comparing the same mapped function 
,f , the result

is that the comprehension is 30% faster than my matching based map function.

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