Created
May 1, 2012 13:20
-
-
Save ashwin/2567864 to your computer and use it in GitHub Desktop.
Range of integers cached by Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python caches a small range of integers (objects) | |
# This is implementation specific and can be discovered easily | |
import platform | |
cacheBegin, cacheEnd = 0, 0 | |
for i in range( -500, 0 ): | |
if i is int(str(i)): | |
cacheBegin = i | |
break | |
for i in range( cacheBegin, 500 ): | |
if i is not int(str(i)): | |
cacheEnd = i - 1 | |
break | |
print( "Python version: {} implementation: {}".format( platform.python_version(), platform.python_implementation() ) ) | |
print( "This implementation caches integers {} to {}".format( cacheBegin, cacheEnd ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment