map del efficiency python2.2 and 2.1

John Hunter jdhunter at nitace.bsd.uchicago.edu
Tue Jul 16 15:07:02 EDT 2002


>>>>> "Alex" == Alex Martelli <aleax at aleax.it> writes:
    Alex> Another likely performance boost in 2.2 would be:

    Alex> m = dict(pairs(seq))

Yes, very nice.  This is the fastest yet.  Using the generator pairs
func in the loop

  for (key, val) in pairs(seq):
      m[key] = int(val)

is indeed a good bit faster than the list comp approach, but slower
than the xrange stride 2 ugly thingie.  But dict(pairs(seq)) is
faster and cleaner than either.  Thanks.

    Alex> Regarding del time, you could measure that directly by doing
    Alex> a "del m" and seeing times before and after; also, just in
    Alex> case (shouldn't matter, but...), you could try gc.disable()
    Alex> and see if that makes a difference.

The reported time required for the 'del m' is miniscule, 0.2s.
Interestingly, though, if I do the 'del m', the extra wait at the end
of the python 2.2 run is dramatically reduced and comparable to that
in 2.1.  gc.disable() did not have an appreciable effect, but after I
read your post I did a google groups search on garbage collection and
found that others have talked about an exponential increase in gc
times:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&safe=off&threadm=mailman.1021733430.3746.python-list%40python.org&rnum=1&prev=/groups%3Fq%3Ddisable%2Bgarbage%2Bcollection%2Bpython%26ie%3DISO-8859-1%26hl%3Den%26btnG%3DGoogle%2BSearch

I'm still experimenting with this and if I figure anything more out,
I'll post.

John Hunter



More information about the Python-list mailing list