PEP 372 -- Adding an ordered directory to collections

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Thu Jun 19 08:53:18 EDT 2008


dbpoko...:
> Which should be 12 bytes on a 32-bit machine. I thought the space for
> growth factor for dicts was about 12% but it is really 100%.

(Please ignore the trailing ".2" in my number in my last post, such
precision is silly).
My memory value comes from experiments, I have created a little
program like this:

from memory import memory

def main(N):
    m1 = memory()
    print m1

    d = {}
    for i in xrange(N):
        d[i] = None

    m2 = memory()
    print m2
    print float((m2 - m1) * 1024) / N
main(20000000)

Where memory is a small module of mine that calls a little known
program that tells how much memory is used by the current Python
process. The results for that run n=20000000 are (first two numbers
are kilobytes, the third number is byte/pair):

1876
633932
32.3612672

It means to store 20_000_000 pairs it requires about 647_000_000
bytes, Python 2.5.2, on Win.

Bye,
bearophile



More information about the Python-list mailing list