Speed Comparison Perl Python & C
bob at redivi.com
Tue Mar 2 22:18:06 CET 2004
On 2004-03-02 15:52:55 -0500, "Neil Hodgson" <nhodgson at bigpond.net.au> said:
> beliavsky at aol.com:
>> Thanks. I am going to learn about Psyco. In this case, I assume that
>> doing the computations with floating point numbers and finally
>> converting the result to int gives the same values as the original
>> integer calculation. In other cases, integer arithmetic will need to
>> be done with integers to ensure correct results.
> Yes, in this case float has enough range. That is something you get to
> determine with any fixed length numeric representation.
>> Python is supposed to be easy (and in general I agree that it is), but
>> your solution requires some knowledge of
>> (1) how integer and floating point calculations are done (which many
>> novices do not have)
>> (2) when Psycho can speed things up
>> and the final result is still much slower than Fortran. For the
>> Fortran program, the only "trick" is the use of integer*8.
> With Fortran, you need to know how large your values are going to become.
> If you increased the number of iterations in your example sufficiently,
> Fortran's 64 bit integers would overflow requiring understanding of the
> concept of fixed range integers. Python avoids this by using unbounded
> integers. Python is oriented towards ease of use and correctness at the
> expense of speed. If the speed of the Python program is inadequate then you
> can take a working Python program and work on its speed. Or decide that the
> speed problem needs another language.
> Python does optimize integers that can be represented in 32 bits but
> larger than that and unbounded integers are used. For some applications, it
> would be better if Python also optimized integers that require between 32
> and 64 bits.
Especially on architectures that have 64 bit integer registers, but are
running on an operating system/compiler combination that uses 32 bits
for int and long (such as the PowerPC 970, on OS X). I would imagine a
similar situation exists for other processor/enivronment combinations.
More information about the Python-list