base64 encoding using the new binary syntax

Bjorn Gustavsson bjorn@REDACTED
Tue Sep 26 10:52:29 CEST 2000


Sean Hinde <Sean.Hinde@REDACTED> writes:

> Some more observations:
> 
> If in the shell you do:
> 
> 74> A=lists:duplicate(40000,3).                         
> [3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3|...]
> 75> B=list_to_binary(A).                                
> <<3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3|... 40000
> bytes>>
> 76> <<B/binary,B/binary>>.
> <<3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3|... 80000
> bytes>>
> 77> A++A.
> [3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3|...]
> 
> <<B/binary,B/binary>> visibly takes ages but A++A. returns immediately!

The evaluation of bit syntax expressions in the shell is done in pure
Erlang. Actually it converts the binaries to lists of bits, combines and
converts the resulting list of bits to a binary. We might optimise this
a little in R8.

In compiled code, the expression

	<<B/binary,B/binary>>

will evaluate much faster than in the shell, but 

	list_to_binary([B|B])

is somewhat faster.

> 
> Also:
> 
> 79> io:format("~p",[<<B/binary>>]). 
> <<3>>ok

This is a bug that has been corrected in R7B.

/Bjorn

-- 
Björn Gustavsson            Ericsson Utvecklings AB
bjorn@REDACTED      ÄT2/UAB/F/P
			    BOX 1505
+46 8 727 56 87 	    125 25 Älvsjö



More information about the erlang-questions mailing list