Extending python - to swig, not to swig or Cython

后端 未结 10 736
栀梦
栀梦 2020-11-30 18:32

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 do

10条回答
  •  一生所求
    2020-11-30 19:25

    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!

    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.

    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.

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

提交回复
热议问题