- The numpy implementation is 60 time faster then a basic python implementation.
- My C++ implementation is a little more then 10 time faster then my simply python numpy implementation.
Friday, May 29, 2009
Is Python really slow? A practical comparison with C++
The common perception is that Python's implementation is slow, but you can often write fast Python if you know how to profile your code effectively.
I have tried it. I have compared a hight cpu intensive algorithm, the training of a simple one hidden neural network. To do so, I have used my old C++ NeuralNetwork library (flayers) and an implementation in python with Numpy. I have wrote a simple neural net in python and optimize all loops with numpy as suggested in a profiling presentation saw in Pycon2009.
I have compare the training time of a simple fully connected NeuralNetwork will 100 hidden neurones for 10 iteration on letters dataset (cost function = mean square error).
Here is the time to do 10 iteration with flayers (c++):
So if you do the math:
Numpy implementation definitly worth it because it reduce the code and has a significant performance impact, the C++ might be required for extreme performance but the trade off of code complexity and time my not work it. Now that I have the choice, I will still use my C++ lib.
Posted by fraka6 at 8:23 PM