Thursday, 1 January 2009

Howcome so many 8s?

Below, you can see plot of the results of the following code:

import sys
for x in range(200):
print x, sys.getrefcount(x)
I read recently that integers less than 256 are being interned by CPython interpreter, so I took a look at how they are used. First 80 integers has about 20 refs, with much bigger number for the initial couple of numbers. Then the refcount is usually less than 10. For some reason, there is a whole lot of references to the number 8.



EDIT: I didnt' notice the 8's leap on debian machine. It's reproducible though on my mac.

1 comment:

Michael Foord said...

Very odd, interesting discovery. :-)