473,771 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

Dec 24 '05 #1
5 2807
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.activestat e.com/ASPN/Cookbook/Python/Recipe/286222>
/Jean Brouwers

Dec 24 '05 #2

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.activestat e.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/pyt...er/310121.html

the old school way is to use funcs like
sys.getobjects( )
sys.gettotalref count() ## Py_REF_DEBUG build
gc.get_objects( )
gc.get_referrer s('')

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/e...s.html#mxTools

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

Dec 24 '05 #3
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.activestat e.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/pyt...er/310121.html

the old school way is to use funcs like
sys.getobjects( )
sys.gettotalref count() ## Py_REF_DEBUG build
gc.get_objects( )
gc.get_referrer s('')

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/e...s.html#mxTools

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


Dec 24 '05 #4

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


also look:

http://spyced.blogspot.com/2005/09/h...on-part-9.html

whihc mentions twisted.python. reflect.findIns tances(sys.modu les, str)
and objgrep, which i didn't know about

Dec 24 '05 #5
gene tani a écrit :
Shahriar Shamil Uulu wrote:
Thank you, for your directions and advices.
shahriar ...


also look:

http://spyced.blogspot.com/2005/09/h...on-part-9.html

whihc mentions twisted.python. reflect.findIns tances(sys.modu les, str)
and objgrep, which i didn't know about


This looks relevant too (not tested though):

http://pysizer.8325.org/

--
Olivier

Dec 24 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
16004
by: Greg Merideth | last post by:
I've written a basic windows service to provide some helper xml functions for my web methods and even thou the service is only about 1k lines long with 1 timer, its mem usage is 10m and its vm mem usage is 14! The same code written as a program that requires you to click on the menu options to fire off the events takes up 4/9mb. I've seen examples where calling SetProcessWorkingSetSize(hWnd, -1, -1); does the same thing as minimizing a...
2
2289
by: Jonas Maurus | last post by:
Hello everybody, I'm pondering the following problem: I want to write a Python program that receives messages via SMTP and stores them in a dict or an array. For my purposes it would be important that all received mail would be kept in RAM and not cached out to disk. If a new message comes in that can't fit in the allocated memory, a number of old messages would be discarded.
2
4753
by: Gary Robinson | last post by:
I'm running a Python job on OS X 10.5.3 and the Python 2.5.2 that's available as a binary download at python.org for OS X. I ran a python program tonight that ended up using much more memory than anticipated. It just kept on using more and more memory. Instead of killing it, I just watched it, using Activity Monitor. I assumed that when it had 2GB allocated it would blow up, because I thought 32-bit python could only address 2GB. But...
0
1090
by: Hendrik van Rooyen | last post by:
"Blubaugh, David A." <dblub....elcan.comwrote: I am running some i/o in a thing called an eBox running Slackware Linux for which GPIO port we have made some I/O boards. This is a very weak machine - 500Mhz 486 without fp, 128Mb ram. Its just cheap, which is why we are using it. I can send it 64 bytes, which it then puts out from userland
0
10260
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10102
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.