I have a problem with understanding the memory_profilers output. Basically, it looks like this:
Filename: tspviz.py
Line # Mem usage Increment Line Contents
================================================
7 34.589844 MiB 34.589844 MiB @profile(precision=6)
8 def parse_arguments():
9 34.917969 MiB 0.328125 MiB a = [x**2 for x in range(10000)]
On the 9th line we can clearly see, that we use some memory. Now, I measured the size of this list with sys.getsizeof(). And I double checked if it is in fact a list of ints:
print(sys.getsizeof(a))
print(type(a[0]))
And this is what I got:
87624
<class 'int'>
Well, now there's a problem. As I was checking, f.e the int in Python is of size 28 on my 64-bit Windows machine. I don't know if that's correct. But even so. 10000 * 28 = 0.28 MB. And 0.28 MB = 0.267028809 MiB (the output from the memory_profiler is displaying MiB). Now the problem is, that in the table there is 0.328125 MiB, so the difference is 0.061096191 MB.
My concern here is, well, is it really that big amount of memory needed to construct a list in Python, or am I interpreting something in a wrong way?
And P.S: Why, when this a list was of length 1000000, the number in the Increment column for this line, when I was creating it, was like -9xxx MiB? I mean why the negative number?