Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to calculate the CPU time consumption and memory consuption of any python program in Linux

57 views
Skip to first unread message

Shahriar Shamil Uulu

unread,
Dec 24, 2005, 5:10:56 AM12/24/05
to
Hi All,
i want to calculate the cpu time consumption and memory consuption of
any program written in python during runtime on Linux Fedora Core - 2,
P4, RAM-512 MB. Actually i have written one database program in two
ways, 1) Inprocedural way 2) in object oriented way. Now i want to
check how efficient each function, object,method and variable is. How i
can do this ?
Any help will be greatly apperciated ...
Thank you ...

MrJean1

unread,
Dec 24, 2005, 12:56:21 PM12/24/05
to
For CPU time usage, see the standard time module

<http://docs.python.org/lib/module-time.html>

specifically the time.clock() function. For memory usage see

<http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286222>


/Jean Brouwers

gene tani

unread,
Dec 24, 2005, 1:18:36 PM12/24/05
to

there was a good long discussion about memory profiling, incluindg some
things that seem to work but don't actually. start here:
http://mail.python.org/pipermail/python-list/2005-November/310121.html

the old school way is to use funcs like
sys.getobjects()
sys.gettotalrefcount() ## Py_REF_DEBUG build
gc.get_objects()
gc.get_referrers('')

and look here:
http://evanjones.ca/python-memory.html
http://codespeak.net/svn/user/nick8325/sizer/
http://pysizer.8325.org/
http://www.softwareverify.com/
http://www.egenix.com/files/python/eGenix-mx-Extensions.html#mxTools

and somebody suggested throttling back memory using "limit vmemory
10000 "

Shahriar Shamil Uulu

unread,
Dec 24, 2005, 1:34:31 PM12/24/05
to
Thank you, for your directions and advices.
shahriar ...

gene tani

unread,
Dec 24, 2005, 1:45:34 PM12/24/05
to

Shahriar Shamil Uulu wrote:
> Thank you, for your directions and advices.
> shahriar ...

also look:

http://spyced.blogspot.com/2005/09/how-well-do-you-know-python-part-9.html

whihc mentions twisted.python.reflect.findInstances(sys.modules, str)
and objgrep, which i didn't know about

Olivier Grisel

unread,
Dec 24, 2005, 3:29:30 PM12/24/05
to pytho...@python.org
gene tani a écrit :

This looks relevant too (not tested though):

http://pysizer.8325.org/

--
Olivier

0 new messages