[Python-Dev] Program runs in 12s on Python 2.7, but 5s on Python 3.5 -- why so much difference?

Antoine Pitrou solipsis at pitrou.net
Tue Jul 18 12:18:06 EDT 2017


On Tue, 18 Jul 2017 12:03:36 -0400
Ben Hoyt <benhoyt at gmail.com> wrote:

> Hi folks,
> 
> (Not entirely sure this is the right place for this question, but hopefully
> it's of interest to several folks.)
> 
> A few days ago I posted a note in response to Victor Stinner's articles on
> his CPython contributions, noting that I wrote a program that ran in 11.7
> seconds on Python 2.7, but only takes 5.1 seconds on Python 3.5 (on my 2.5
> GHz macOS i7), more than 2x as fast. Obviously this is a Good Thing, but
> I'm curious as to why there's so much difference.
> 
> The program is a pentomino puzzle solver, and it works via code generation,
> generating a ton of nested "if" statements, so I believe it's exercising
> the Python bytecode interpreter heavily.

A first step would be to see if the generated bytecode has changed
substantially.

Otherwise, you can try to comment out parts of the function until the
performance difference has been nullified.

Regards

Antoine.




More information about the Python-Dev mailing list