Arrays vs tuples / lists
Carsten Schultz
cschultz@REDACTED
Tue May 18 17:23:25 CEST 2004
On Tue, May 18, 2004 at 03:07:01PM +0200, Erik Stenman wrote:
> > On Tue, May 18, 2004 at 01:05:35PM +0200, Thomas Johnsson wrote:
> > > Hi,
> > > thanks for doing the benchmarking for me.
> > > One note: the ets lookup is done with
> > > [X] = ets:lookup(Tab, Pos),
> > > which involves a pattern matching on the lhs, that has a cost.
> > > Could you re-run it on the same box, with
> > > X = head(ets:lookup(Tab, Pos)),
> > >
> > > or some such? Head must do a similar check, but presumably
> > it is cheaper.
> >
> > If the second version is faster, then the Erlang compiler is
> > stupid, and I do not think that it is.
> >
> > Or is there any semantic difference between the two that I
> > have overlooked?
>
> There is a small difference:
> [X] Guarantees that the length is 1
> hd(X) Guarantees that the length is > 1
^
>=1
Sorry, I must have been half asleep :-)
I then modify my statement that I would be worried if
[X|_] = List
was less efficient than
X = head(List).
Indeed I would hope both to produce exactly the same code.
Greetings,
Carsten
--
Carsten Schultz (2:38, 33:47), FB Mathematik, FU Berlin
http://carsten.fu-mathe-team.de/
PGP/GPG key on the pgp.net key servers,
fingerprint on my home page.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20040518/1ccce441/attachment.bin>
More information about the erlang-questions
mailing list