4 ms·
No. Here's some guys demonstrating 5000x+ speedup by rewriting Python code in C and C++: http://codegolf.stackexchange.com/questions/26323/how-slow-is-python-re
by bjourne 12y ago
No. Here's some guys demonstrating 5000x+ speedup by rewriting Python code in C and C++: http://codegolf.stackexchange.com/questions/26323/how-slow-is-python-really-or-how-fast-is-your-language http://codegolf.stackexchange.com/questions/26323/how-slow-i... and http://codegolf.stackexchange.com/questions/26371/how-slow-is-python-really-part-ii http://codegolf.stackexchange.com/questions/26371/how-slow-i...
- nine_k 12y agoPython was sped up 30x, according to the same post, so the difference between best Python and best C++ becomes "mere" ~170 times. Of course, on numeric problems like this, plain CPython inevitably sucks performance-wise (no JIT, a lot of lookups, no value types).
- bjourne 12y agoAt least I linked some numbers. Your statement "usually Python is only a few hundred times slower than C++" is so vague it is completely useless. The Python code was sped up by replacing idiomatic Python with non-idiomatic code (not your "usual" Python) and also replacing a large part of it with calls to optimized code written in C. If your claim had been "Python is only a few hundred times slower if you outsource most of your work to C libraries" I would have had no objection. But that's not what you wrote.
- GFK_of_xmaspast 12y agoIt's simply not a fair comparison if you change the algorithms between implementations.
- olavk 12y agoThat is somewhat misleading, since the optimized versions use different algorithms. There is also an optimized Python version that runs 30 times faster. It is a combination of better algorithms and closer-to-the-metal language that gives the 5000x speedup described in the thread. You can get arbitrary large speedups by just choosing a worse initial algorithm and then improve it.