Gmpy

Alex Martelli aleax at aleax.it
Thu Aug 7 11:31:35 EDT 2003


Jean-Pierre Andreaux wrote:

> Gmpy module was a wrapper of the GNU MP library. It seems that no
> evolution is done on this module since 2001. Indeed, Gmpy is not
> supported in Python 2.2 nor 2.3.

*blink* ...isn't it...?

[alex at lancelot src23x]$ python
Python 2.3+ (#1, Aug  5 2003, 17:15:06)
[GCC 3.2.2 (Mandrake Linux 9.1 3.2.2-3mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gmpy
>>> print gmpy.comb(10,7)
120
>>>

I'll admit I haven't been working on gmpy for a while (it basically
needs more docs, and I don't really needs those docs myself, so it's
tempting to put other things higher on my list of priorities...:-),
but if it had broken with 2.2 or 2.3 I'd surely have fixed it (I tend
to run the current releases of Python -- including "latest from CVS",
very often -- and gmpy's an indispensable companion for me...


> My question is the following: what is the better replacement solution
> for manipulating long numbers. I want to do long numbers
> exponentiations. Thanks in advance for your answers.

Well, let's see...:

[alex at lancelot Lib]$ python timeit.py -s'import gmpy' \
> 'gmpy.mpz(162362341232431)**2313'
1000 loops, best of 3: 1.84e+03 usec per loop

[alex at lancelot Lib]$ python timeit.py -s'import gmpy' \
> '162362341232431**2313'
10 loops, best of 3: 4.3e+04 usec per loop

Apparently, good old gmpy still has some advantage (about 20 times faster)
for exponentiations of this kind, ever when compared to the new and
improved Python 2.3.  With Python 2.2, still according to timeit.py's
report about it, this operation took 3.53e+05 usec per loop in pure
Python -- almost another 10 times more! -- but still 1.85+03 with
gmpy, so with 2.2 gmpy's advantage was almost 200 times on this one.

Anyway, even if you just need a speedup of 20 times, it seems to me
that gmpy can still be of use to you.  What problems, exactly, have
you had using it with Python 2.3...?


Alex





More information about the Python-list mailing list