3 ms·
> Finally, for comparison we implemented this in simple C++ (nothing fancy) without any Python. One would expect that the C++ code would be faster but surprisin
by pjin 15y ago
> Finally, for comparison we implemented this in simple C++ (nothing fancy) without any Python. One would expect that the C++ code would be faster but surprisingly, not by much! Given the fact that it's so easy to develop with Python, this speed reduction is not very significant.
This is the problem I have with Python+Scipy v. MATLAB/C++/YourFavoritePlatform comparisons. I agree that Python code can be clean and clear, but once you start to worry about vectorizing, inlining, manual loop optimizations, or a C or Fortran FFI, then you end up with the same solution that say MATLAB users have to deal with by writing mex functions in C.
Granted there are differences between Language A v. Language B, one may be more concise or their functions are _even higher-order_ than the other's. Point is, once you go down the road of "let's optimize this dynamic language script," your choices are not that different. You lose the "ease" of developing with Python, and if you really performance then it's ultimately inferior to just writing it in C++ or even Fortran.
- andreasvc 15y agoI think you're forgetting the scenario where you have a lot of Python code and only a small part is performance critical. You can speed that part up with something like Cython, and directly integrate it with the rest of the code. If you would have to rewrite it all in C++ it would be a tedious and buggy process, the same goes for ad-hoc interfacing with text files.
- juiceandjuice 15y agoMany times performance computing is about 1% optimizable code and 99% setup. Python is much lovelier for that 99% than matlab is.
- Derbasti 15y agoI have done that in the past. But writing a mex function is a lot more tedious than writing a weave.inline string. Think of all the type conversions you have to put up with in mex. Think about how you have to set up a compile infrastructure and how you have to recompile manually for every target platform. In most cases, I will use weave.inline only for the innermost loop, and all the compilation issues and type conversions will be taken care of for me.