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

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

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 :)
 
Top