[Python-Dev] Optionally using GMP to implement long if available

Victor Stinner victor.stinner at haypocalc.com
Tue Nov 4 18:38:12 CET 2008

Le Monday 03 November 2008 18:56:37 Paul Miller, vous avez écrit :
> Rather than that, what about patching Python's long implementation 
> to use GMP if it's available, and the default implementation if not?

Yes, I like this suggestion of two flavors. Python with GMP and Python without 
GMP (builtin integer library). It's "easy" to change the long type 
implementation since only few modules use PyLong internals:
 - mashal: import/export (.pyc)
   => core function might be moved to longobject.c
 - math: use some special features of the PyLong type
   => macro can be written for that
or simplify a #ifdef.

I first wrote a patch in January 2008 to test Python3 + GMP. After your email 
I updated my patch and fix it to pass most regression tests. Depending of the 
patch version, the overhead (of using GMP instead a builtin library) is 
between 14% and 3% (Python is slower with GMP). I used pystone which is not a 
math application.

More details at:

Victor Stinner aka haypo

More information about the Python-Dev mailing list