how many objects are loaded for hello world?

Fredrik Lundh fredrik at pythonware.com
Wed Sep 17 02:30:14 EDT 2008


belred wrote:

> i just read this blog about how many objects (types) are loaded for a
> hello world program in C#.
> 
> http://blogs.msdn.com/abhinaba/archive/2008/09/15/how-many-types-are-loaded-for-hello-world.aspx
> 
> how can you find out how many are loaded for a python program:  print
> 'hello'

types and objects are different things, though.  to get an idea of how 
much stuff Python loads using upstart, do "python -vv script.py" or add

     import sys
     print len(sys.modules), "modules"
     print sys.modules.keys()

to the end of the script.

to get an idea of how many objects and types that are created at that 
point, add

     import gc
     print len(gc.get_objects()), "objects"
     print len(set(map(type, gc.get_objects()))), "types"

this gives me 35 modules (including the gc module), 3219 objects and 26 
distinct types -- but the above will miss things, so the true numbers 
are a bit higher.

(you might be able to use a debug build to get more detailed information)

</F>




More information about the Python-list mailing list