2

if i write a program in Python and then compile it using any of these compilers:

Gordon McMillan’s installer (cross-platform)

Thomas Heller’s py2exe

(Windows) Anthony Tuininga’s cx_Freeze (cross-platform)

is it as fast as code written in a compiled language?

3 Answers 3

14

These tools are not compilers, they're just packaging python code into an easier to launch application. If you want something more like compilation try http://pypy.org (JIT for python) or http://code.google.com/p/shedskin (which translates Python to C++).

Sign up to request clarification or add additional context in comments.

1 Comment

Note that the former is still an interpreter (a smart one that provides considerable speedups for most code, but still not faster than AOT-compiled C except for carefully constructed benchmarks that have little to do with real programs) and the latter only accepts a small "sufficently static" subset of Python. For that matter, RPython (by the guys behind PyPy, and in fact used for PyPy) does something similar but probably better (they've figured out a really clever approach and had lots of time to improve it - OTOH I'm biased).
2

For speed, you may also want to look into Cython that allows writing C extensions for Python in a Python-like language.

Comments

1

Google recently released Grumpy which transpiles Python to Go prior to compiling it. The expectation is that the software will run much faster this way, and to bypass the infamous Python GIL, allowing true multithreading.

Grumpy is a Python to Go source code transcompiler and runtime that is intended to be a near drop-in replacement for CPython 2.7. The key difference is that it compiles Python source code to Go source code which is then compiled to native code, rather than to bytecode. This means that Grumpy has no VM. The compiled Go source code is a series of calls to the Grumpy runtime, a Go library serving a similar purpose to the Python C API (although the C API is not directly supported).

1 Comment

Of course, it does not mean it's actually faster that way. Of course, even if it's slower, that doesn't mean it will always be slower.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.