Most efficient solution?

Terry Reedy tjreedy at home.com
Sat Jul 21 07:47:16 CEST 2001


"Christopher A. Craig" <com-nospam at ccraig.org> wrote in message
news:mailman.995674715.6446.python-list at python.org...
> -----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.

I know this was not your main point, so thank you for running these.
I'm going to replace 1.5.2 with 2.1.1 soon, so could not do this
myself yet.  Your result is about what I expected based on previous
comparisons.

TJ Reedy






More information about the Python-list mailing list