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

Discussion in 'Python' started by Shahriar Shamil Uulu, Dec 24, 2005.

  1. 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 ...
     
    Shahriar Shamil Uulu, Dec 24, 2005
    #1
    1. Advertising

  2. Shahriar Shamil Uulu

    MrJean1 Guest

    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
     
    MrJean1, Dec 24, 2005
    #2
    1. Advertising

  3. Shahriar Shamil Uulu

    gene tani Guest

    MrJean1 wrote:
    > 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


    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 "
     
    gene tani, Dec 24, 2005
    #3
  4. Thank you, for your directions and advices.
    shahriar ...

    gene tani wrote:
    > MrJean1 wrote:
    > > 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

    >
    > 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, Dec 24, 2005
    #4
  5. Shahriar Shamil Uulu

    gene tani Guest

    gene tani, Dec 24, 2005
    #5
  6. Re: How to calculate the CPU time consumption and memory consuptionof any python program in Linux

    gene tani a écrit :
    > 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
    >


    This looks relevant too (not tested though):

    http://pysizer.8325.org/

    --
    Olivier
     
    Olivier Grisel, Dec 24, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. qazmlp
    Replies:
    4
    Views:
    6,063
    Darren Dunham
    Oct 15, 2004
  2. Wim Deprez

    plotting cpu and mem consumption

    Wim Deprez, Jun 17, 2004, in forum: C++
    Replies:
    3
    Views:
    504
    Wim Deprez
    Jun 18, 2004
  3. Jonas Maurus
    Replies:
    2
    Views:
    292
    Jeremy Sanders
    Sep 20, 2007
  4. black-white

    big cpu consumption

    black-white, Aug 17, 2008, in forum: Java
    Replies:
    13
    Views:
    691
  5. Guillaume Ebuprofen
    Replies:
    1
    Views:
    119
    Robert Klemme
    Oct 22, 2010
Loading...

Share This Page