Jim Jewett wrote:
> On 4/26/06, Antoine Pitrou <[EMAIL PROTECTED]> wrote:
> 
>>2) set([1,2,3]) makes little sense anyway, since it
>>probably isn't significantly more efficient than [1,2,3]
> 
> 
> In the current implementation, is is less efficient.
> 
> But a set is what you really intend; using a list simply because it is
> currently more efficient is a bad thing to encourage.

I my not-at-all-scientific tests, sets were faster when the set is 
created ahead of time, but just barely, except when you were testing 
something that was at the front of the list.  Tuples were always a bit 
slower than sets or lists.

But if you factor in the expense of actually creating the 
set/list/tuple, then the different is more significant; a little less 
than a factor of three between tuples and lists (since tuples can be 
allocated once), and a little less than a factor of three between lists 
and sets when building the set from a list (which is what everyone has 
been using as examples), or a little less than a factor of two when 
building from a tuple.

I imagine a set literal would improve the set case a little, but since 
it hashes its arguments it's always going to have more overhead to 
create than a list.  If you could create a *frozen* set with a literal, 
that should outperform lists and tuples.

But I should note that I didn't do very thorough testing at all, just 
tested loops that used "in" on a three-item container (and in py2.4).

-- 
Ian Bicking  /  [EMAIL PROTECTED]  /  http://blog.ianbicking.org
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to