扩展Python - 痛饮,不痛饮,或用Cython [英] Extending python - to swig, not to swig or Cython

查看:208
本文介绍了扩展Python - 痛饮,不痛饮,或用Cython的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现我的Python code中的瓶颈,与心理等发挥各地然后决定写一个C / C ++的扩展性能。

I found the bottleneck in my python code, played around with psycho etc. Then decided to write a c/c++ extension for performance.

随着痛饮的帮助,你几乎不需要关心的参数等一切工作正常。

With the help of swig you almost don't need to care about arguments etc. Everything works fine.

现在我的问题:痛饮创建了一个相当大的PY-文件,做了很多'checkings'和'PySwigObject'的调用实际.pyd或的.so code之前

Now my question: swig creates a quite large py-file which does a lot of 'checkings' and 'PySwigObject' before calling the actual .pyd or .so code.

没有任何人有任何经验,是否有一些性能来获取,如果你手工写这个文件还是让痛饮做到这一点。

Does anyone of you have any experience whether there is some more performance to gain if you hand-write this file or let swig do it.

推荐答案

有关确保你将永远有一个性能提升的手这样做,但比起这样做所需的工作量,增益会很小。我没有任何数字给你,但我不建议这样做,因为你将需要保持手的接口,如果你的模块是很大,这是不是一种选择!

For sure you will always have a performance gain doing this by hand, but the gain will be very small compared to the effort required to do this. I don't have any figure to give you but I don't recommend this, because you will need to maintain the interface by hand, and this is not an option if your module is large!

您确实要选择,因为你想快速发展,使用脚本语言正确的事情。这样你可以避免早期优化综合征,现在你想优化的瓶颈部分,太棒了!但是,如果你做手工的C / Python接口你会爱上肯定早期优化综合征。

You did the right thing to chose to use a scripting language because you wanted rapid development. This way you've avoided the early optimization syndrome, and now you want to optimize bottleneck parts, great! But if you do the C/python interface by hand you will fall in the early optimization syndrome for sure.

如果您希望用更少的接口code的东西,你可以想想从C code创建一个DLL,并直接从蟒蛇使用该库的 cstruct

If you want something with less interface code, you can think about creating a dll from your C code, and use that library directly from python with cstruct.

也考虑用Cython 如果你希望只使用蟒蛇code程序中的。

Consider also Cython if you want to use only python code in your program.

这篇关于扩展Python - 痛饮,不痛饮,或用Cython的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆