0

I'm writing an app in Python that uses among others PySide for the GUI and also modbus_tk for Modbus communications between my PC and an embedded controller.

I've noticed that when I byte-compile my script to a Windows application (.exe), using py2exe, the requests are sent to the controller slower than with the Python script (.py).

Have you ever experienced something like this ? Is it normal ? What should I do to speed up my program ? Any help would be highly valued.

AdrienW
  • 1,951
  • 2
  • 18
  • 42

1 Answers1

1

From https://en.wikipedia.org/wiki/Py2exe

Although this program transforms a .py file to an .exe, it does not make it run faster as py2exe just bundles the Python bytecode rather than converting it to machine-code. It may even run slower than using the Python interpreter directly because of startup overhead.

You can't compile (standard) Python code.

Paul
  • 275
  • 1
  • 9
  • So it comes from _py2exe_... Do you suggest I try another converter (like _cx_Freeze_) or is it a lost cause ? I'll try [this](http://stackoverflow.com/questions/138521/is-it-feasible-to-compile-python-to-machine-code) in the meantime – AdrienW Jun 22 '16 at 08:31
  • 1
    There is plenty ways to speed up Python code (multiprocessing, lazy programing, ...) but compiling is not. If you really want to go ultra-fast, you could consider recoding the heavy (in algorithmic sense) part of your code in a compiled language and call it from Python (with Popen for example) – Paul Jun 22 '16 at 09:59
  • Thanks for your advice ! I think my Python code is pretty efficient though, what takes time is the Modbus communication (takes longer with the .exe than with the .py). Perhaps I should convert the library I'm using to C/C++... – AdrienW Jun 22 '16 at 11:04