ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

Which is better; compiled binaries or interpreted code in python?

I'm planning to use python to build a couple of programs to be used as services, run from PHP code later on. In terms of performance, which is faster, to compile the python code into a binary file using cx_freeze or to run the python interpreter each time I run the program? Deployment environment: OS: Arch Linux ARM Hardware: Raspberry Pi [700MHz ARMv6 CPU,256MB RAM, SD Card filesystem] Python Interpreter: Python2.7 App calls frequency: High

user-image
تم إضافة السؤال من قبل Badr Ghatasheh , Software Engineer , bayt.com
تاريخ النشر: 2013/07/23
THIKRALLAH SHREAH
من قبل THIKRALLAH SHREAH , Technical Team Leader , bayt.com

Well, I'm not a python expert per say, yet I used py2exe in the past.
The intention of such applications is packaging code, from my experience with py2exe and what I have understood from it's documentation it will load the original scripts into the interpreter.
That means there is no performance difference between them in terms of performance.If you are looking for very fast performance package, always think "C", http://docs.python.org/2/extending/extending.html if you want to try that out.
I would recommend to do a bench marking for cx_freeze.
and it will be nice gesture from you to share it back here.

code that is portable is best. Any language that is compiled creates binaries. Some binaries fail on some machines. Having a non-compiled code like python and shell-bash scripts is good but not always fast.

Haruna Bala Magaji
من قبل Haruna Bala Magaji , System Administrator , KEDCO

Binary it's a Machine code that can be executed directly without translation so it's easier. But for me It's better to use interpreter because it include source code and it can also bypass and execute code directly

Mustafa Rawi
من قبل Mustafa Rawi , CEO , Cubex Solutions

Python is compiled (to machine code) at run-time every time either from source code (.py) or from byte code (.pyc or .pyo).

Python is compiled at first run into byte code in .pyc files (python compiled). If your .py files are more recent, Python will re-compile your files and replace the old .pyc files.

Python compiled files can be optimized, just a little so far, into .pyo files. To compile files in optimized format, run Python interpreter using '-o' flag without quotes.

You can double the optimization by using the flag '-oo' without quotes. In some rare cases, this may damage your code and render it unusable. This flag is not recommended unless you know exactly what you are doing.

Access rights may prevent the interpreter from generating the byte code compilation of your .py files.

Finally, and to answer your question, performance is not affected unless your .py files are too large. This is due to loading time only, not execution time.

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟