Reputation: 534
I'm creating an image detection module, and I do a lot of math calculations around arrays.
I know that C/C++’s array iterates faster than Python’s
I can't move my project to C/C++, so I wanted to create an array module in C/C++ and call it in Python.
What I want to know:
1) Is this viable? Or calling a module from another interpreter will slow down my program more than it will speed it up?
2) Is there some Python package that does what I want?
I feel like I haven’t written enough info, but I can't think of anything else important.
[EDIT] So I just went with numpy and it has everything I need :p, thanks everyone
Upvotes: 0
Views: 119
Reputation: 100
Try boost.python
.
If you can port all the computational heavy stuff to C++, it'll be quite fast but if you need to switch continuously between C++ and python, you won't get much improvement.
Upvotes: 0
Reputation: 1537
I think Cython might worth looking into. It can give some drastic speed improvements and is quite similar to what you are describing.
Upvotes: 2
Reputation: 313
It will most likely speed things up (especially if you do it for long). The only overhead will probably be at the interfacing. The c/c++ code will run however it is compiled to be ran. Though if you are just looking to wrap arrays only, you should probably take a look at other solutions first.
For interfacing python and c/c++ take a look at the post here .There's quite a few suggestions provided
Upvotes: 0
Reputation: 275770
Both the array and the low level operations on it would have to be in C++; switching on a per element basis will have little benefit.
There are many python modules that have internal C/C++ implementations. Simply wrapping a C or C++ style array would be pointless, as the built in python data types can basically be that.
Upvotes: 3