Arrays vs tuples / lists
Tue May 18 15:07:01 CEST 2004
> 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
but as I said [X] is probably slightly faster.
More information about the erlang-questions