<div dir="ltr">Thanks for testing.<div><br></div><div>Oddly, I just tested it in Linux (Ubuntu), and get the same results as you -- Python 2.7.13 outperforms 3 (3.5.3 in my case) by a few percent. And even under a Virtualbox VM it takes 3.4 and 3.6 seconds, compared to ~5s on the host macOS operating system. Very odd. I guess that means Virtualbox is very good, and that clang/LLVM is not as good at optimizing the Python VM as gcc is.</div><div><br></div><div>I can't find anything majorly different about my macOS Python 2 and 3 builds. Both look like they have PGO turned on (from sysconfig.get_config_vars()). Both have HAVE_COMPUTED_GOTOS=1 but USE_COMPUTED_GOTOS=0 for some reason. My Python 2 version is the macOS system version (/usr/local/bin/python2), whereas my Python3 version is from "brew install", so that's probably the difference, though still doesn't explain exactly why.</div><div><br></div><div>-Ben</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 24, 2017 at 1:49 PM, Wang, Peter Xihong <span dir="ltr"><<a href="mailto:peter.xihong.wang@intel.com" target="_blank">peter.xihong.wang@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Ben,<br>
<br>
Out of curiosity with a quick experiment, I ran your pentomino.py with 2.7.12 PGO+LTO build (Ubuntu OS 16.04.2 LTS default at /usr/bin/python), and compared with 3.7.0 alpha1 PGO+LTO (which I built a while ago), on my SkyLake processor based desktop, and 2.7 outperforms 3.7 by 3.5%.<br>
On your 2.5 GHz i7 system, I'd recommend making sure the 2 Python binaries you are comparing are in equal footings (compiled with same optimization PGO+LTO).<br>
<br>
Thanks,<br>
<br>
Peter<br>
<div><div class="h5"><br>
<br>
<br>
-----Original Message-----<br>
From: Python-Dev [mailto:<a href="mailto:python-dev-bounces%2Bpeter.xihong.wang">python-dev-bounces+<wbr>peter.xihong.wang</a>=<a href="mailto:intel.com@python.org">intel.com@<wbr>python.org</a>] On Behalf Of Nathaniel Smith<br>
Sent: Tuesday, July 18, 2017 7:00 PM<br>
To: Ben Hoyt <<a href="mailto:benhoyt@gmail.com">benhoyt@gmail.com</a>><br>
Cc: Python-Dev <<a href="mailto:python-dev@python.org">python-dev@python.org</a>><br>
Subject: Re: [Python-Dev] Program runs in 12s on Python 2.7, but 5s on Python 3.5 -- why so much difference?<br>
<br>
I'd probably start with a regular C-level profiler, like perf or callgrind. They're not very useful for comparing two versions of code written in Python, but here the Python code is the same (modulo changes in the stdlib), and it's changes in the interpreter's C code that probably make the difference.<br>
<br>
On Tue, Jul 18, 2017 at 9:03 AM, Ben Hoyt <<a href="mailto:benhoyt@gmail.com">benhoyt@gmail.com</a>> wrote:<br>
> Hi folks,<br>
><br>
> (Not entirely sure this is the right place for this question, but<br>
> hopefully it's of interest to several folks.)<br>
><br>
> A few days ago I posted a note in response to Victor Stinner's<br>
> articles on his CPython contributions, noting that I wrote a program<br>
> that ran in 11.7 seconds on Python 2.7, but only takes 5.1 seconds on<br>
> Python 3.5 (on my 2.5 GHz macOS i7), more than 2x as fast. Obviously<br>
> this is a Good Thing, but I'm curious as to why there's so much difference.<br>
><br>
> The program is a pentomino puzzle solver, and it works via code<br>
> generation, generating a ton of nested "if" statements, so I believe<br>
> it's exercising the Python bytecode interpreter heavily. Obviously<br>
> there have been some big optimizations to make this happen, but I'm<br>
> curious what the main improvements are that are causing this much difference.<br>
><br>
> There's a writeup about my program here, with benchmarks at the bottom:<br>
> <a href="http://benhoyt.com/writings/python-pentomino/" rel="noreferrer" target="_blank">http://benhoyt.com/writings/<wbr>python-pentomino/</a><br>
><br>
> This is the generated Python code that's being exercised:<br>
> <a href="https://github.com/benhoyt/python-pentomino/blob/master/generated_solv" rel="noreferrer" target="_blank">https://github.com/benhoyt/<wbr>python-pentomino/blob/master/<wbr>generated_solv</a><br>
> e.py<br>
><br>
> For reference, on Python 3.6 it runs in 4.6 seconds (same on Python<br>
> 3.7 alpha). This smallish increase from Python 3.5 to Python 3.6 was<br>
> more expected to me due to the bytecode changing to wordcode in 3.6.<br>
><br>
> I tried using cProfile on both Python versions, but that didn't say<br>
> much, because the functions being called aren't taking the majority of the time.<br>
> How does one benchmark at a lower level, or otherwise explain what's<br>
> going on here?<br>
><br>
> Thanks,<br>
> Ben<br>
><br>
> ______________________________<wbr>_________________<br>
> Python-Dev mailing list<br>
> <a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-dev</a><br>
> Unsubscribe:<br>
> <a href="https://mail.python.org/mailman/options/python-dev/njs%40pobox.com" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/options/python-dev/<wbr>njs%40pobox.com</a><br>
><br>
<br>
<br>
<br>
--<br>
</div></div>Nathaniel J. Smith -- <a href="https://vorpus.org" rel="noreferrer" target="_blank">https://vorpus.org</a> ______________________________<wbr>_________________<br>
<span class="">Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-dev</a><br>
</span>Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/peter.xihong.wang%40intel.com" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/options/python-dev/<wbr>peter.xihong.wang%40intel.com</a><br>
</blockquote></div><br></div>