I just wrote this primitive script:
from sys import getsizeof as g
x = 0
s = ''
while s != 'q':
x = (x << 8) + 0xff
print(str(x) + " [" + str(g(x)) + "]")
s = input("Enter to proceed, 'q' to quit ")
The output is as follows - and quite surprising, as I perceive it:
255 [28]
65535 [28]
16777215 [28]
4294967295 [32]
1099511627775 [32]
281474976710655 [32]
72057594037927935 [32]
18446744073709551615 [36]
And so on. My point is: it seems that the variable x has some sort of 'overhead' with a size of 25 bytes. Where does this come from? Thanks in advance for any attempt to help me.
-
Everything is an object in Python.juanpa.arrivillaga– juanpa.arrivillaga2017年07月11日 18:39:39 +00:00Commented Jul 11, 2017 at 18:39
1 Answer 1
A python int is an object, so it's not surprising that it has a small overhead.
If this overhead starts to become meaningful for you then this implies you're manipulating substantial collections of ints, which suggests to me that the numpy library is probably something you should consider.
3 Comments
array.array, or struct