Use GMP as default implementation of integers in Python3

Hans Aberg haberg at math.su.se
Wed Nov 5 20:21:16 CET 2008


On 5 Nov 2008, at 01:16, Victor Stinner wrote:

> I wrote a patch for the Python language to use the GMP library for the
> integers. My patch works correctly but Python is a little bit  
> slower (3% to
> 14%) because most of the time, integers are (very) small. I guess  
> that the
> most common range is [-2^32-1; 2^32-1]. Should I use a better memory
> allocator? I also changed it to use Python memory managment. How  
> can I speed
> it Python+GMP?

I am told (in the context if C++ implementations) that overflow  
checks take up much time. So  the user should be able to choose both  
fixed sized integral types (like 'int', for time optimization) and  
variable size (when needed).

Standard C/C++ allocations (malloc, new) take up much time, and  
should be avoided if time is critical. Use a GC, if dynamic  
allocations are needed, or a sufficiently large array or 'alloca'.

The page
   http://en.wikipedia.org/wiki/Python_%28programming_language%29
says Python uses reference counting GC, which is about what one can  
implement in C++ proper, which is slow if used on a low level. But  
are two-space copying GC's as use in for example the Haskell  
interpreter Hugs <http://haskell.org/hugs/>.

   Hans




More information about the gmp-discuss mailing list