PEP 372 -- Adding an ordered directory to collections

Duncan Booth duncan.booth at invalid.invalid
Thu Jun 19 15:09:47 CEST 2008


bearophileHUGS at lycos.com wrote:

> 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.
> 

What do you get if you change the output to exclude the integers from 
the memory calculation so you are only looking at the dictionary 
elements themselves? e.g.

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

    d = {}
    for i in keys:
        d[i] = None

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


-- 
Duncan Booth http://kupuguy.blogspot.com



More information about the Python-list mailing list