python speed

mensanator at aol.com mensanator at aol.com
Tue Nov 29 22:04:15 EST 2005


Krystian wrote:
> Hi
>
> >>are there any future perspectives for Python to be as fast as java? i
> >>would like to use Python as a language for writing games.
> >
> >Why would we want Python to be as fast as Java when it's already faster?
>
> hm... i came across this site:
> http://shootout.alioth.debian.org/benchmark.php?test=all&lang=java&lang2=python&sort=fullcpu
>
> could you take an attitude with regard to this benchmark?

Benchmarks are worthless. By that I mean they have no value
to me. What matters is the performance on real problems, such
as generating the 1st 6th Generation Type [1,2] Mersenne Hailstone
Collatz sequence.

That's a BIG number and needs BIG arithmetic to solve. Java has
a BigInteger module and can solve it in less than 10 minutes:

C:\Python23\user\pyjava>java Collatz  2 177149 1

Processing time: 571690
x/2  iterations: 1531812
3x+1 iterations: 854697

The arguments evaluate to 2**177149-1. And because this is a
Mersenne number, the sequence diverges until it's over 280000 bits
before converging to 1 bit after 2386509 iterations.

But is 571 seconds a reasonable amount of time for such a difficult
problem?

Compare it to Python with the GMPY module:

C:\Python23\user\pyjava>collatz.py 2 177149 1
r1 1531812 r2 854697 in 72.9869999886 seconds

Yes, it would appear that in this real world application Java is
ridiculously slow. Of course, Python is doing the heavy lifting
with GMPY which is a compiled C program with a Python
wrapper. But so what? Maybe the reason I use Python is
BECAUSE the math module is compiled C. Duh. With Python/GMPY
I get the high level power I need for the algorithms without
sacrificing the low level muscle I need for the heavy arithmetic.

> 
> >Take a look at PyGame.
> 
> on my way :)
> 
> best
> k




More information about the Python-list mailing list