[erlang-questions] map over bitstring

Tony Rogvall tony@REDACTED
Fri Oct 22 13:16:41 CEST 2010


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