Lua is faster than Fortran???

Teemu Likonen tlikonen at iki.fi
Sun Jul 4 04:28:32 EDT 2010


* 2010-07-04 10:03 (+0200), Stefan Behnel wrote:

> The main reason why Python is slow for arithmetic computations is its
> integer type (int in Py3, int/long in Py2), which has arbitrary size
> and is an immutable object. So it needs to be reallocated on each
> computation. If it was easily mappable to a CPU integer, Python
> implementations could just do that and be fast. But its arbitrary size
> makes this impossible (or requires a noticeable overhead, at least).
> The floating point type is less of a problem, e.g. Cython safely maps
> that to a C double already. But the integer type is.

You may be right. I'll just add that Common Lisp's integers are of
arbitrary size too but programmer can declare them as fixnums. Such
declarations kind of promise that the numbers really are between
most-negative-fixnum and most-positive-fixnum. Compiler can then
optimize the code to efficient machine instructions.

I guess Python might have use for some sort of

    (defun foo (variable)
      (declare (type fixnum variable))
      ...)



More information about the Python-list mailing list