I’m sure you and I have seen at least one video on YouTube about C++ being faster than Python. Although this is true, the way they show Python in their videos is rather humiliating.
But Python actually IS fast. The best example for this is the RecursionError. Basically, it alerts you if your code is basically looping in itself forever.
Python iterates anywhere from 999 times (in a compiler like Programiz) to 2976 times (in Jupyter Notebook) to ensure it truly is a RecursionError.
Thirty years ago you could read similar in discussion forums like comp.lang.*. It is a recurring trope I’ve seen, but most of those touting the speed of language X vs language Y never show what speed is necessary for their needs. I work with Electronic Design Automation, (EDA), tools that help design and verify integrated circuits. The vendor tools do the heavy lifting in some compiled language which is fine, but when the engineer uses those tools, they tend to want to string them together in a certain way, or extract custom reports, or edit the internal data flow of the tool in design specific ways. Doing that kind of job in Python gives me code I can extract bits out of to show the engineer who wants to automate his manual work; I am automating something that may take hours otherwise, on start-to-end computations that can take overnight to weekends. a Python script that takes an extra twenty minutes and is easy to validate and maintain beats out a C++ or C equivalent that might take two minutes to run, but in the overall scheme of things, that compiled tool runtime saving does not matter. Getting the result at 06:02 in the morning instead of 06:30 makes no difference when work starts at nine (and the early bird may check at 07:30 ).
Compiled language speed kings have their place, but so has Python; and more people have realised that over the decades.
Is that supposed to be impressive? You didn’t even say how fast it did that. I estimate I’ve washed my hands 150000 times. I guess that’s very fast then?
Together with your strange “Python iterates [some number of times] to ensure it truly is a RecursionError”, I’m getting the feeling you’re misunderstanding what’s happening there…
@shashTheCoder I’m starting to suffer the Sheldon’s Syndrome, so I don’t really know if this is sarcasm. I hope it is!
In case it’s not, have you tried to put a simple counter in an identical C++ program, print the counter and see what little number it prints when the same Python program stops?
Furthermore, have you ever considered searching on the official docs about recursion, the meaning of “maximum recursion depth exceeded”, even if I suppose the message itself is quite illuminating… or maybe simply asking to your favorite AI why Python is so blasting “fast”?
That would certainly be impressive if you used a time travel sink. But maybe Quincy Reynard is the only one who can use that.
(Edit: Actually, I don’t know how many years you’ve been on the planet, but that works out to roughly forty years of washing your hands ten times a day, so, that is quite impressive.)
So why use a language as slow as C++? Why not use C, or assembler?
For that matter, C++ and Rust are both complicated languages, but Rust is complicated for better reasons. So why use a needlessly complicated language like C++?
I tried it on Compiler Explorer and the Python code really beats C++ unless C++ uses -O3 optimization. But Compiler Explorer is known to randomly use machines from their matrix, so I’ll rerun on my own computer when I can. ↩︎
No reason for profanity when you know little. I don’t see the point, frankly, of this post. You demonstrate how Python fails with a recursion error, because it is a high-level language and puts guardrails in place against stupid behaviour like overly deep recursion without a base case (which can be altered with sys.setrecursionlimit). In lower-level languages, you are expected not to do that in your code, and it cannot be detected at compile time because the halting problem is undecidable. Python is by little means fast, but it is very useful as a scripting language or for code that isn’t performance-critical. It failing earlier at runtime means nothing.