开发者

Convert python script to binary executable

I wrote a number crunching python code. The calculations involved can take hours. Is it possible somehow to compile it to binary?

Tha开发者_如何学Gonks


Not in any useful (for you) way, but moving the calculations into NumPy or Cython will speed them up.


First you can try psyco, that may give you a speed up as much as 10x, but 2x is more typical

If you can post the code up somewhere, perhaps someone can point out how to leverage numpy.

If your task doesn't map well only numpy then cython is a good choice to convert a intensive function or two into C code just by adding a few cdefs.

If you can show us the code (even just the hot spots) we can probably give you better advice.

Perhaps you can modify your algorithm


Shedskin might be worth a try.

From their front page blurb:

Shed Skin is an experimental compiler, that can translate pure, but implicitly statically typed Python programs into optimized C++. It can generate stand-alone programs or extension modules that can be imported and used in larger Python programs.

Besides the typing restriction, programs cannot freely use the Python standard library (although about 20 common modules, such as random and re, are currently supported). Also, not all Python features, such as nested functions and variable numbers of arguments, are supported (see the tutorial for details).

For a set of 44 non-trivial test programs (at over 10,000 lines in total (sloccount)), measurements show a typical speedup of 2-40 times over Psyco, and 2-220 times over CPython. Because Shed Skin is still in an early stage of development, however, many other programs will not compile out-of-the-box.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜