How to make Python run as fast (or faster) than Julia

Terry Reedy tjreedy at udel.edu
Fri Feb 23 03:11:36 EST 2018


On 2/22/2018 10:31 PM, Python wrote:

>> Why do you care about the 50 million calls? That's crazy -- the important
>> thing is *calculating the Fibonacci numbers as efficiently as possible*.

> If you are writing practical programs, that's true.  But the Julia
> benchmarks are not practical programs; they are designed to compare
> the performance of various language features across a range of
> languages.

If that were so, then the comparison should use the fastest *Python* 
implementation.  Which is what the article discussed here did.  But the 
comparison is a lie when the comparison is compiled machine code versus 
bytecode interpreted by crippled cpython*.  And people use this sort of 
benchmark to choose a language for *practical programs*, and don't know 
that they are not seeing *Python* times, but *crippled cpython* times.

* Python has an import statement.  But 'comparisons' disallow 'import 
numpy', a quite legal Python statement, and similar others.  The ability 
to import Python wrappers of Fortran and C libraries is part of the 
fundamental design of cpython.  It is a distributed project.

The fact that numerical python, numarray, and now numpy are distributed 
separately, in spite of proposals to include them, syntax additions for 
their benefit, and their overwhelming usefullness, is a matter of social 
and administrative convenience, not necessity.  There is also a 
proposal, which I consider likely to happen, to enhance the cpython 
Windows and Mac installers by making installation of numpy and other 
great 'external' modules selectable options.

It takes just 2 or 3 legal Python lines that do run with cpython as 
installed to make 'import numpy' work, without resorting to subprocess 
(though that is *also* legal python:

from ensurepip import bootstrap; bootstrap()  # only if needed
from pip import main
main(['install', 'numpy'])
<wait 70 seconds>
 >>> import numpy
 >>> dir(numpy)
['ALLOW_THREADS', 'AxisError', 'BUFSIZE', 'CLIP', 'ComplexWarning',
...
'vstack', 'warnings', 'where', 'who', 'zeros', 'zeros_like']

So, given a realistic number-crunching benchmark that take at least 
several minutes, one could add those two lines at the top and be off

-- 
Terry Jan Reedy




More information about the Python-list mailing list