which is more useful in the real world? Python or C++...

which is more useful? Python or C++

  • Python

  • C++


Results are only viewable after voting.

ExSan

Active Member
On a somewhat related comparison, I ported C++ code to price financial derivatives (options) to Python to get a feeling for relative run-time performance., This is essentially a one-step algorithm in a double nested 'for' loop and random number generators are used in both cases (Mersenne Twister 19937)
Conclusion C++ is 60 times faster!

Just looking at the random number generator part, using Numba improves performance appreciably (Python is 1 1/2 times slower). In more complicated code it is not obvious how to use numba. In this case 'pure' Python would not be suitable for production purposes but it would be useful for prototyping.
60 times faster!!!!
you said it all
 

longgamma

Active Member
C++ Student
On a somewhat related comparison, I ported C++ code to price financial derivatives (options) to Python to get a feeling for relative run-time performance., This is essentially a one-step algorithm in a double nested 'for' loop and random number generators are used in both cases (Mersenne Twister 19937)
Conclusion C++ is 60 times faster!

Just looking at the random number generator part, using Numba improves performance appreciably (Python is 1 1/2 times slower). In more complicated code it is not obvious how to use numba. In this case 'pure' Python would not be suitable for production purposes but it would be useful for prototyping.
Did you use Numpy's random library to initialize the random numbers in Python?

I really appreciate Ipython/Jupyter notebook's approach to iterate through a tough problem step by step. Some data structures in python like lists are relatively inefficient compared to say a numpy series. Additionally, vectorizing code to remove for loops helps a lot as well.
 

Daniel Duffy

C++ author, trainer
yes, I used Random indeed and it was faster.
Contrary to the Zen of Python, there are multiple solution to a given problem..

There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
 

Daniel Duffy

C++ author, trainer
"which is more useful in the real world? Python or C++..."

Of course, looking back, the question itself is wrong. Too binary.
 

longgamma

Active Member
C++ Student
yes, I used Random indeed and it was faster.
Contrary to the Zen of Python, there are multiple solution to a given problem..

There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Well numpy is built on C, no wonder it is so fast :)
 

longgamma

Active Member
C++ Student
yes, I used Random indeed and it was faster.
Contrary to the Zen of Python, there are multiple solution to a given problem..

There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Sure Numpy isn't part of the standard library - just like Boost isn't. Numpy also takes in tensors and matrices as inputs, so you can apply exponent to an entire matrix for example, while the standard library would fail to do so. So its use case is for scientific computing and therefore it is more powerful (especially the ufuncs) than the standard math library in Python.
 

Quasar Chunawala

Active Member
Having acknowledged Python is great for rapid prototyping, to my mind, practicalities are important. Any large quant shop would have a considerable codebase in C++, especially for performance reasons. Learning C++ therefore would be a good strategy. Also, I feel, C++ supports multiple paradigms and lends itself well to a wide array from problems spanning multiple fields.
 
Last edited:
Top