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

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Feb 23 13:00:33 EST 2018


On Fri, 23 Feb 2018 12:17:50 +0000, bartc wrote:

> On 23/02/2018 01:27, Steven D'Aprano wrote:
>> On Thu, 22 Feb 2018 17:53:30 +0000, bartc wrote:
> 
>>> The actual result is irrelevant, so long as its correct. The important
>>> thing is those 50 million calls.
>> 
>> Why do you care about the 50 million calls?
> 
> Because we are interested in comparing call-efficiency across languages?

Are we? What on earth makes you think that?


[...]
> You're responsible for implementing the call-mechanism of a new
> language, and you want to make it efficient. What program do you test it
> with, one that contains zero calls (clearly, that will be most
> efficient!), or one that contains lots of calls?

This has nothing to do with the topic under consideration. It is 
irrelevant. This discussion has nothing, absolutely nothing with 
"implementing the call-mechanism of a new language".

Perhaps you have missed that Python is a mature language well over 20 
years old now, and even Julia is a few years old.


[...]
> OK, then, if you are at all interested in Julia vs. Python (and it was
> you who posted that article!), then compare a version of a benchmark
> that uses as few calls as possible, if you like. But what exactly is
> that benchmark then highlighting? Loops?

What on earth makes you think that the point of this is to highlight any 
one particular feature of a language? Loops, calls, addition, who cares?

The point is to show how to take badly written slow code written in 
Python, and modify it to be better, faster code while remaining within 
the Python ecosystem.


[...]
> OK, then do as I did, and keep a global tally of how many calls it
> makes, and print that as the result. Then the correct output for
> 'fibcalls(36)' should be:
> 
>    48315633
> 
> If yours shows only 37, then /your/ program is wrong.

I'm not interested in such a function. The words have not yet been 
invented to explain how little I care about how fast Python or Julia can 
make millions and millions of pointless function calls for no good reason.

But if it makes you feel good about yourself, if it makes you feel that 
you've won some sort of little victory, then I concede:

If a programmer cares about writing useless, crappy, pointless code that 
just makes function call after function call for no good reason, then 
Python will be terrible for the job. I would never use Python for such 
code, it is awful at it.

If you think it is important to run an empty loop a billion times in a 
nanosecond, Python will be crap at that too.

Python is only useful for writing useful, meaningful code that gets 
useful work done, not for your "fibcalls" function. If you have a need 
for "fibcalls", then go ahead and use Julia, or C, or whatever language 
you prefer, and be glad that you have a wide choice of languages to 
choose from.


-- 
Steve




More information about the Python-list mailing list