Ask Your Question

lola's profile - activity

2019-11-18 18:51:25 +0200 received badge  Notable Question (source)
2019-11-18 18:51:25 +0200 received badge  Popular Question (source)
2011-10-03 21:06:40 +0200 received badge  Supporter (source)
2011-10-03 21:06:38 +0200 received badge  Scholar (source)
2011-10-03 21:06:38 +0200 marked best answer get_memory_usage returning negative numbers

You're using get_memory_usage incorrectly -- it returns the amount of memory used at a given point in time. If you pass in a number to it, then it will return the difference between the current memory usage and the number you passed in. For example,

sage: get_memory_usage()
875.8515625
sage: t = get_memory_usage()
sage: get_memory_usage(t)
0.0

So, in your usage, it's just subtracting toy(1000) from the current memory usage.

If you're interested in doing more "in-depth" memory profiling than what get_memory_usage can offer, you should look into heapy.

2011-10-03 21:06:11 +0200 answered a question get_memory_usage returning negative numbers

Thank you for your help! I'll definitely look into heapy.

2011-10-02 21:35:52 +0200 received badge  Editor (source)
2011-10-02 21:13:59 +0200 asked a question get_memory_usage returning negative numbers

Is there a reason that get_memory_usage should ever return a negative number?

I tried running a "toy" program (after get_memory_usage returned surprisingly large numbers on a more complicated program that I'm using in my research - I wanted to see what the standard memory usage should look like for a basic counter function) and here is what happened:

def toy(n):
    c = 0
    for k in xrange(0, n):
        c = c+1
    return c

get_memory_usage(toy(1000))
-464.0859375

I could be misunderstanding how get_memory_usage works, but it seems to me that the memory usage should never be negative!

(In case this is relevant, I am using Sage 4.7.1 on my laptop.)