Most efficient solution?

Christopher A. Craig com-nospam at ccraig.org
Sat Jul 21 02:17:12 CEST 2001


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Terry Reedy" <tjreedy at home.com> 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 ccraig.org>
Perl is worse than Python because people wanted it worse -- Larry Wall
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Processed by Mailcrypt

iEYEARECAAYFAjtYyggACgkQjVztv3T8pztQNQCaA3MNfa6wr3eHuBHhPA20te2t
hjcAn0CFRVX+SJ3p2gEDjiTSPI41sCbM
=DwzQ
-----END PGP SIGNATURE-----




More information about the Python-list mailing list