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

Chris Angelico rosuav at gmail.com
Mon Feb 26 14:50:21 EST 2018


On Tue, Feb 27, 2018 at 6:37 AM, Rick Johnson
<rantingrickjohnson at gmail.com> wrote:
> On Monday, February 26, 2018 at 4:39:22 AM UTC-6, Steven D'Aprano wrote:
>> On Sun, 25 Feb 2018 19:26:12 -0800, Rick Johnson wrote:
>>
>> > On Friday, February 23, 2018 at 8:48:55 PM UTC-6, Steven D'Aprano wrote:
>> > [...]
>> > > Take the Fibonacci double-recursion benchmark. Okay, it
>> > > tests how well your language does at making millions of
>> > > function calls. Why?
>> >
>> > Because making "millons of function calls" is what
>> > software *DOES*!
>>
>> You're right -- I worded that badly, and ended up saying
>> something I didn't really mean. Mea culpa.  Of course over
>> the course of the entire program run, most non-trivial
>> programmers will end up having millions (if not billions)
>> of function calls *in total*. But they're not all happening
>> *together*.
>
> So what? Latency is latency. And whether it occurs over the
> course of one heavily recursive algorithm that constitutes
> the depth and breadth of an entire program (a la fib()), or
> it is the incremental cumulative consequence of the entire
> program execution, the fact remains that function call
> overhead contributes to a significant portion of the latency
> inherent in some trivial, and *ALL* non-trivial, modern
> software.

By saying "the fact remains", you're handwaving away the work of
actually measuring that function call overhead is "significant". Can
you show me those numbers? Steve's point is that it is NOT
significant, because non-toy functions have non-trivial bodies. If you
wish to disagree, you have to demonstrate that the function call is
*itself* costly, even when there's a real body to it.

> I'm very glad you brought this up, because it proves my main
> point that, Python's maximum recursion error is one feature
> they got _right_. If you don't like the default recursion
> limit of 1000, or maybe 1000 recursions is breaking a valid
> recursive algorithm, you can set the recursion limit to
> whatever you like...
>
>     ## Python 2 ##
>     >>> import sys
>     >>> sys.setrecursionlimit
>     <built-in function setrecursionlimit>
>     >>> sys.setrecursionlimit(10)
>     >>> count = 1
>     >>> def bad():
>     ...     global count
>     ...     print count
>     ...     count += 1
>     ...     bad()
>     ...
>     >>> bad()
>     1
>     2
>     3
>     4
>     5
>     6
>     7
>     8
>     9
>     Traceback (most recent call last):
>       File "<stdin>", line 1, in <module>
>       File "<stdin>", line 5, in bad
>       File "<stdin>", line 5, in bad
>       File "<stdin>", line 5, in bad
>       File "<stdin>", line 5, in bad
>       File "<stdin>", line 5, in bad
>       File "<stdin>", line 5, in bad
>       File "<stdin>", line 5, in bad
>       File "<stdin>", line 5, in bad
>       File "<stdin>", line 5, in bad
>     RuntimeError: maximum recursion depth exceeded
>
> It is however unfortunate that we get slamed with N
> recursive exception messages :-(, but hey, at least we can
> modify the maximum recursion limit! It's a step in the right
> direction. :-)

Ah, been a while since you tried Python 3, is it? :)

  [Previous line repeated X more times]

ChrisA



More information about the Python-list mailing list