[erlang-questions] lists:member efficiency

Ulf Wiger <>
Sun Nov 25 17:55:02 CET 2007


2007/11/25, Andrew Arrow <>:
>
> If the list has over 100,000 items would
> lists:member keep up okay?

This simple test can give you an idea:

Eshell V5.5.4  (abort with ^G)
1> L = lists:seq(1,100000).
[1,
 2,
... 29|...]
2> timer:tc(lists,member,[100000,L]).
{994,true}
3> timer:tc(lists,member,[100001,L]).
{995,false}

This is a crude measure of the worst-case performance
of using lists:member/2 on a list of 100,000 elements -
namely hitting the last object in the list (well, the worst
case is actually when no object is found, but the difference
falls within the margin of error.)

Normally, you'd reckon that half this cost will be your
average cost, but YMMV.

BR,
Ulf W



More information about the erlang-questions mailing list