Most efficient solution?

Christopher A. Craig com-nospam at
Fri Jul 20 20:17:12 EDT 2001

Hash: SHA1

"Terry Reedy" <tjreedy at> writes:

> To compare program running times, they should compute the same thing.
> How long does dict2 take if you remove the not, so it makes the list
> of 1500 elements that revised dict does, instead of the 'not' list of
> 6000?
> How long does dict take if you feed filter with 'lambda x,
> f=c.has_key: f(x)', so it make the 'not' list of 6000 elements?

dict2 without the not takes (predictably) about twice as long as dict
(.038 seconds vs. .019) (because the explicit loops in the list
comprehensions are slower)

dict with a not takes (also predictably) slightly longer than dict2
(.06 vs .055) (because the overhead of a lambda is higher than the loops)

My point was not to compare dict to dict2, but to show that the
original author's comp() was greatly outperformed by a proper
dictionary solution.

(Note that I'm using a new computer, so the numbers don't align with
the one I used for the first set of tests)

- -- 
Christopher A. Craig <com-nospam at>
Perl is worse than Python because people wanted it worse -- Larry Wall
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Processed by Mailcrypt


More information about the Python-list mailing list