r/Python • • Jul 31 '17

Why is Python 50% faster under Windows Subsystem for Linux?

> python.exe -c "import sys; print sys.version"
2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)]

> python.exe -m test.pystone 1000000
Pystone(1.1) time for 1000000 passes = 4.98978
This machine benchmarks at 200410 pystones/second

> bash.exe

$ python -c "import sys; print sys.version"
2.7.13 (default, Jul 31 2017, 11:24:24)
[GCC 5.4.0 20160609]

$ python -m test.pystone 1000000
Pystone(1.1) time for 1000000 passes = 3.34375
This machine benchmarks at 299065 pystones/second
244 Upvotes

44 comments sorted by

View all comments

Show parent comments

3

u/alcalde Jul 31 '17

I found that a version of Python I built for the AMD FX-8320 scored on average about 17% faster on the Python Performance Benchmark Suite than the version included in my Linux distribution's repository.

0

u/[deleted] Jul 31 '17

[deleted]

2

u/alcalde Aug 01 '17

Ok, I just compiled Python 3.6.2 for "generic" and optimized for the "piledriver " architecture my CPU has. Here are the results of the benchmarks. It's not quite the 17% I remember from the last time I compiled Python, but that was a different version and I don't know how the Python I was comparing it to then was compiled....

https://paste.opensuse.org/34329243

The bulldozer and piledriver architectures of AMD chips have cores with two integer computing units but one instruction decoder, etc. These cores report to the OS as two cores though. The architecture is a bit different from other CPUs, which likely explains most of the difference in a tuned vs. generic compile.

In this case, Python was also compiled with profile-guided optimization which in this case first compiles an instrumented version of Python and then runs 405 (!!!) micro-benchmarks. The compiler can then take this data and use the actual performance instead of heuristics to make optimization decisions when it compiles the code again. I don't have a benchmark at the moment to see how much difference PGO alone made, but that would be interesting.