Python and GMP.

Paul Rubin http
Tue Apr 21 14:43:29 CEST 2009

alessiogiovanni.baroni at writes:
> > Could you test pow(a,b,c) where a,b,c are each 300 decimal digits?
> > This is an important operation in cryptography, that GMP is carefully
> > optimized for.  Thanks.
> Ok, thanks for your answers. I understand the problems of licensing,
> but we could to learn from GMP's source code to improve the Python's
> int implementation, mainly because, GMP is very fast. 

GMP is a lot more complicated than Python bigint arithmetic.  It's
optimized separately for many different cases and operations.  It uses
assembly language for innder loops.  And the modular exponential
operation pow(a,b,c) is especially carefully tuned in complicated
ways.  Python tries to just have straightforward, reasonably portable

I did something like

     import gmpy
     pow=gmpy.modexp # or whatever it was called
   except ImportError: 

in an application a while back, so that it would use gmpy if possible
and Python longs otherwise.  That worked pretty well.

More information about the Python-list mailing list