looping through the keys of a dictionary

Alex Martelli aleax at aleax.it
Mon Aug 27 04:39:44 EDT 2001


"Markus Schaber" <markus at schabi.de> wrote in message
news:5285736.frOyU7HbjW at lunix.schabi.de...
    ...
> Using python 1.5.2 on Linux, I get:
> schabi at lunix:~/python/dict$ python dict.py
> using keys: 0.41
> using items: 0.42
    ...
> However, using python2.0.1, I get nearly the same values as you:
> schabi at lunix:~/python/dict$ python2 dict.py
> using keys: 0.42
> using items: 0.53
    ...
> This lets me to the following conclusions:
> - Your Machine speed seems to be in the 500Mhz Athlon class :-)

Peculiar indeed -- it's a 300MHz Pentium-2 running NT4 (lots
of RAM though, and a very good overall implementation -- it's
a HP Kayak box).


> - Key Access seems to be faster on Linux than on NT - or dict access
> slower on linux (when your machine is slower than mine)

Yep.  I'll try on Linux, too, when I can.


> - Python 2 is slightly slower in dictionary lookup (or general code
> execution), but it needs 25% more time using keys.

Looks like some memory-allocation/deallocation issue having
to do with the generation of lots of pairs (2-item tuples) --
but I thought those had been optimized going to Python 2,
not de-optimized.


Alex






More information about the Python-list mailing list