0

I am working on a script someone created for modifying 3D digital models that was written in Python code. The original author compiles the file into a Windows executable before distributing it. I'm guessing he uses py2exe or some similar tool.

My question is, is there any speed benefit in doing so? The script is very slow, and I'm hoping for better performance after compiling the script. Thanks.

2
  • 1
    Try it and time it Commented Jan 25, 2018 at 18:47
  • Depending on the code, you could probaly compile parts of, or the whole code with numba. If there are only numpy arrays with eccesiive looping involved numba would be a good alternative. For example take a look here stackoverflow.com/questions/45399851/… Commented Jan 26, 2018 at 12:34

1 Answer 1

3

No. py2exe and similar tools just create a bundle including the Python interpreter, the bytecode of your Python sources and their dependencies. It's just a deploy convenience, there's no speed advantage (besides skipping the initial parsing of the .py files; in this respect, it's like running your code the second time when the .pyc files are already created).

For "out of the box" performance improvement you can try running your script with PyPy instead of CPython - for "all interpreted" (=> no numpy & co.) numerical Python code I saw very often 20x speedups.

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

6 Comments

Can I use PyPy to compile scripts into executables? Will they run faster than regular compiled Python scripts?
@posfan12: PyPy is a JIT compiler (it compiles to machine code at runtime after examining the "typical" code paths of the interpreted code), so by itself it cannot generate a "classical", ahead-of-time compiled binary. As for the "exe bundle" trick generally used for CPython by py2exe e PyInstaller, AFAIK they don't work with PyPy. Most probably your script will run faster, but there's no simple way to deploy it without explicitly installing PyPy as well.
Can I install regular Python and PyPy on the same machine at the same time? Are scripts called in a different way on the command line?
Yes. No (well, you have to write pypy instead of python, but that's about it).
I will probably just switch to another (compiled) programming language.
|

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.