Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to measure memory footprint of Python objects?

Reply
Thread Tools

How to measure memory footprint of Python objects?

 
 
Neagu, Adrian
Guest
Posts: n/a
 
      09-20-2006
Hello everybody,

I try to solve the following problem: I have a python program that takes a
lot of memory (>hundred Mb). I made an improvement (I hope) and I want to
measure the gain (if possible on several platforms). I would like to be able
to print the max memory taken during the run upon exiting my Python program
(like I already do for the time taken to run).

I can see the total process size of the Python process (Task manager on MS
Win or Unix "ps" command) but that is not precise enough for me and also not
convenient. I don't care about the python interpreter overhead, I'm
interested only in the total size of Python objects allocated by my program.
Is there a Python way to get that (meaning without resorting to
non-portable, less precise OS features)?

I would like to get that size at different given moments in time to make up
a timeline of memory consumption. But, if that is too tricky, I would be
happy to just get the maximum.

Any suggestion welcome,
Adrian.
 
Reply With Quote
 
 
 
 
Paul Rubin
Guest
Posts: n/a
 
      09-20-2006
"Neagu, Adrian" <(E-Mail Removed)> writes:
> I would like to get that size at different given moments in time to make up
> a timeline of memory consumption. But, if that is too tricky, I would be
> happy to just get the maximum.
>
> Any suggestion welcome,


See the docs for the gc module.
 
Reply With Quote
 
 
 
 
AdrianNg3
Guest
Posts: n/a
 
      09-20-2006
Paul Rubin wrote:
> See the docs for the gc module.


This is the first place I've checked. I see no useful info there about
the actual size of the objects (bytes occupied in memeory).

The closest thing to what I need is get_objects( ). Then I have to go
over the list
and do something with the objects. Wouldn't that be too slow?

Thanks anyway,
Adrian.

 
Reply With Quote
 
Heikki Toivonen
Guest
Posts: n/a
 
      09-21-2006
Neagu, Adrian wrote:
> I try to solve the following problem: I have a python program that takes a
> lot of memory (>hundred Mb). I made an improvement (I hope) and I want to
> measure the gain (if possible on several platforms). I would like to be able
> to print the max memory taken during the run upon exiting my Python program
> (like I already do for the time taken to run).


You could try PySizer: http://pysizer.8325.org/

--
Heikki Toivonen
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Using virtual memory and/or disk to save reduce memory footprint nick C++ 58 03-16-2009 01:08 PM
Re: How to measure memory footprint of Python objects? Fredrik Lundh Python 1 09-20-2006 01:08 PM
Thumbnail creation with small memory footprint. gbrun Java 1 02-19-2006 11:35 AM
JMS memory footprint size Beatrice Rutger Java 0 06-05-2005 09:56 PM



Advertisments