Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile python into binary - pypy performance

I am looking to compile python source code into a binary. I generally use pypy for performance reasons (my application runs significantly faster using pypy). I found this answer from 2012 stating compiling pypy into binary isn't possible using any of the existing tools (e.g. pyinstaller). Compile PyPy to Exe. I wasn't quite able to follow what the top response was explaining as a solution.

I am wondering:

  1. Is there now a reasonably easy way to compile python code to binary using pypy as the interpreter?

  2. I don't actually need to use pypy, I just use it for the performance gains. Is there a reasonable way to avoid using pypy but still get similar performance gains? This would still need to support compiling to binary.

As an additional note, I use the 2.7 syntax.

like image 988
Matt Avatar asked Jun 19 '17 13:06

Matt


People also ask

How much faster is PyPy?

On the average, PyPy speeds up Python by about 7.6 times, with some tasks accelerated 50 times or more. The CPython interpreter simply doesn't perform the same kinds of optimizations as PyPy, and probably never will, since that is not one of its design goals.

Does compiling Python make it faster?

It's worth noting that while running a compiled script has a faster startup time (as it doesn't need to be compiled), it doesn't run any faster. It's worth noting that while running a compiled script has a faster startup time (as it doesn't need to be compiled), it doesn't run any faster. A common misconception.

Why is PyPy faster than Python?

PyPy often runs faster than CPython because PyPy uses a just-in-time compiler. Most Python code runs well on PyPy except for code that depends on CPython extensions, which either does not work or incurs some overhead when run in PyPy.

Why is PyPy slower than Python?

Because of the inherent dynamism of Python, it's impossible to compile Python into a standalone binary and reuse it. PyPy is a runtime interpreter that is faster than a fully interpreted language, but it's slower than a fully compiled language such as C.


1 Answers

you can take a look to nuitka ( http://nuitka.net/doc/user-manual.html)

 nuitka --standalone --recurse-on --python-version=2.7 main.py
like image 113
MinhNV Avatar answered Oct 06 '22 21:10

MinhNV