[Python-ideas] Expansion of the range of small integers
Antoine Pitrou
solipsis at pitrou.net
Mon Sep 17 15:29:01 CEST 2012
On Mon, 17 Sep 2012 15:41:23 +0300
Serhiy Storchaka <storchaka at gmail.com>
wrote:
> Now in the CPython small integer numbers from -5 up to 256 inclusive are
> preallocated at the start. It allows to reduce memory consumption and
> time of creation of the integers in this range. In particular this
> affects the speed of short enumerations. Increasing the range to the
> maximum (from -32767 to 32767 inclusive), we can speed up longer
> enumerations.
>
> Microbenchmarks:
> ./python -m timeit "for i in range(10000): pass"
> ./python -m timeit -s "a=[0]*10000" "for i, x in enumerate(a): pass"
> ./python -m timeit -s "a=[0]*10000" "i=0" "for x in a: i+=1"
> ./python -m timeit -s "a=[0]*10000" "for i in range(len(a)): x=a[i]"
>
> Results:
> non-patched patched
> 530 usec 337 usec 57%
> 1.06 msec 811 usec 31%
> 1.34 msec 1.13 msec 19%
> 1.42 msec 1.22 msec 16%
See also http://bugs.python.org/issue10044
> 1) Memory consumption increases by constant 1-1.5 MB.
That sounds a bit annoying. Is it for a 32-bit or 64-bit build?
Regards
Antoine.
--
Software development and contracting: http://pro.pitrou.net
More information about the Python-ideas
mailing list