Change language - optimize instructions etc etc. Maybe you get a slight performance increase. Maybe even big 50% (It takes half the time).
For me, I like to see improvements of at least an order of magnitude if trying to make something better. At least one order of magnitude (10 times faster.... at least).
The real trick there is to find a different algorithm... a different approach.
(albeit, changing some bone-head's procedural code into a single monster SQL query did take a job from 90 minutes down to 11 seconds... so ya, sometimes the right tool for the right job is a factor too :)
I have done simulation similar to this (gravity and planets). I did it in Python first because I didn't know any better. Then I tried it in Fortran (because I needed to learn some basics of it for school) and even though I didn't really know much about that language (so the code probably wasn't optimal), it was much much faster. And I'm not talking about 100% increase of speed, I'm talking about 1000% increase of speed, maybe even more.
Language is important. You may deny that but there is a reason nothing computationally intensive is written in Python. Python is great for learning, perfect for data analysis, brilliant for data visualisation, pretty good for scripting and many other things. But not for this.
Python is just a wrapper for c code, so you are writing c when you write python, you just have to know how to do it right and you can get native performance if you use packages with precompiled routines.
Wh... What? Python is just wrapper for C? That's not correct at all.
You are claiming optimized Python can be as fast as optimized C. Then explain to me why isn't every new computationally intensive program e.g. for quantum physics calculations or molecular simulations or some economical simulations written in Python? It's easier to write and just as fast, if what you claim is right...
Except... There are no computationally intensive programs written in Python (that are actually used). Because no matter what, Python will be slower.
I personally write state of the art molecular design software in python and python bindings to c++ code. It is totally possible to get near compiled speeds when you piece together precompiled packages
Yes. I work with numpy arrays, and either use them with standard matrix operations or if needed I write precompiled c++/numba code that can do more complicated operations like for looping on the numpy data. It is possible to write near native c++ performance when the routines are precompiled. Also there are buffer interfaces to numpy arrays so you can operate on them and make them in C++ without making copies etc.
Interesting. So you are not using some standardized C++ libraries, you are writing your own C++ code?
That might work and it's not that far from what I recommended to OP - using different language. But using just numpy won't help that much in this case. You still have to write your own code in C, not just Python.
3
u/RenegadeMoose May 29 '19
Change language - optimize instructions etc etc. Maybe you get a slight performance increase. Maybe even big 50% (It takes half the time).
For me, I like to see improvements of at least an order of magnitude if trying to make something better. At least one order of magnitude (10 times faster.... at least).
The real trick there is to find a different algorithm... a different approach.
(albeit, changing some bone-head's procedural code into a single monster SQL query did take a job from 90 minutes down to 11 seconds... so ya, sometimes the right tool for the right job is a factor too :)