gmpy 1.01 rc near... anybody wanna test>

mensanator at aol.com mensanator at aol.com
Sat Nov 12 19:13:13 EST 2005


mensanator at aol.com wrote:
> casevh at comcast.net wrote:
> > What processor are you running?
>
> Drat, didn't see this before I left work. I'm fairly certain it was a
> Pentium 4, definitely 1.7GHz, Win2000 and Python 2.3.
>
> So I thought I would run the test again on my home computers,
> a Pentium 4 1.5 GHz WinXP Python 2.3 and a laptop with a
> Celeron 2.8 GHz WinXP Python 2.4.
>
> Here are the Celeron/Python2.4 numbers (and original test times)
>
> BF: 27.89 sec  gen6  (31.92)
> CF: 0.203 sec  gen9  (0.234)
>  V: 5.062 sec  gen9  (8.766)
>

Oops, accidentally hit the send button. I didn't give you the
results from my home desktop machine. And those are
interesting.

I did not intend for this test to be a benchmark, simply to
make sure gmpy (and my library of Collatz Functions) were
working properly. Can you imagine my shock at the reults
of the closed form test:

gmpy.version: 1.01

Closed form: Type12MH(k,i)
Find ith, kth Generation Type [1,2] Mersenne Hailstone
using the closed form equation

2**(6*((i-1)*9**(k-1)+(9**(k-1)-1)/2+1)-1)-1

            2**5-1  generation: 1 0 seconds
           2**29-1  generation: 2 0 seconds
          2**245-1  generation: 3 0.015 seconds
         2**2189-1  generation: 4 0 seconds
        2**19685-1  generation: 5 0 seconds
       2**177149-1  generation: 6 0.219 seconds
      2**1594325-1  generation: 7 29.22 seconds
     2**14348909-1  generation: 8 5295 seconds

That's 88 minutes for the gen8 test alone (gen9 is still running).
I was expecting a quarter second for the entire test! I realize that
my office pc and my home pc are configured differently but there
shouldn't be that much difference with the same version of Python
and gmpy.

At first I thought it was locking up, but it didn't have the symptoms
of a lockup: menus still worked, Task manager didn't report not
responding, and sure enough, it completed gen7 eventually.

I finally figured it out, though. I had been toying with my Collatz
Functions and made what I thought was a trivial change:

Original function
def Type12MH(k,i):
	"""Find ith, kth Generation Type [1,2] Mersenne Hailstone
                using the closed form equation

	Type12MH(k,i)
	k: generation
	i: member of generation
	returns Hailstone (a)
	"""
	if (k<1) or (i<1): return 0
	a = (i-1)*9**(k-1) + (9**(k-1) - 1)/2 + 1
	return 2**(6*a - 1) - 1

Now I know better than to allow coersion to mpz's to take place
inside a loop, but this function doesn't loop. Nevertheless, I changed
it to

def Type12MH(k,i):
	"""Find ith, kth Generation Type [1,2] Mersenne Hailstone
                using the closed form equation

	Type12MH(k,i)
	k: generation
	i: member of generation
	returns Hailstone (a)
	"""
	ONE = gmpy.mpz(1)
	TWO = gmpy.mpz(2)
	SIX = gmpy.mpz(6)
	NIN = gmpy.mpz(9)

	if (k<1) or (i<1): return 0

	i = gmpy.mpz(i)
	k = gmpy.mpz(k)

	# a = (i-1)*9**(k-1) + (9**(k-1) - 1)/2 + 1
	# return 2**(6*a - 1) - 1

	a = (i-ONE)*NIN**(k-ONE) + (NIN**(k-ONE) - ONE)/TWO + ONE
	return TWO**(SIX*a - ONE) - ONE

And this was what is making my home desktop run so slow
(at least with mega-bit sized numbers). As soon as I updated the
Collatz Library, I got normal reults:

BF: 37.11 sec  gen6
CF: 0.563 sec  gen9
 V: 1.093 sec  gen9

(Verified by setting it back to original.)

Wow. Didn't realize things were that sensitive. Looks like I'll
have to review a lot of my programs.

> >
> > I only have Windows running on an old Pentium 3. It is easy for me to
> > build a version that will running on almost any recent processor. I'm
> > willing to try and override the CPU detection and make a processor
> > specific build for you. I won't be able to test it, though.
> > 
> > Thanks for the testing!
> > 
> > Case




More information about the Python-list mailing list