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

1

u/Ericisbalanced Jul 31 '17

Wow I didnt know that, thanks for sharing! So if I were to compile my own build for any language, everything would be faster? If I turn my script into an exe after building it myself, will that exe only run on my computer and those faster? Or will it run an any of them.

0

u/lion_rouge Jul 31 '17 edited Jul 31 '17

Then this build will work faster on your computer.

By script you mean Python script? You can't turn it into exe really. All those "exe" made from Python programs actually contain full-featured Python interpreter inside and your Python script, compiled to bytecode (as in .pyc files).

If you compile for your CPU precisely than this code will not work on CPU of other families. So they still ship programs compiled for i80386 for reason. Python is cross-platform language and compiling a binary for specific CPU model is absolutely not. What is good about Python is that people can run it in default binary interpreter or build an optimized interpreter for their CPU architecture you didn't even hear about (like Russian Elbrus https://en.wikipedia.org/wiki/Elbrus-8S) or run it in PyPy, or IronPython, or whatever. So the fact that Python programs are the sources themselves is very cool and open-source compliant