3 ms·
The same code is faster (and easier) to write, correctly, in Python than in either C or C++. (this depends a little on what you're writing, but not much: C/C++
by tehwalrus 11y ago
The same code is faster (and easier) to write, correctly, in Python than in either C or C++. (this depends a little on what you're writing, but not much: C/C++ make you specify much more about your code than python does.)
The same code, however, will run faster on C/C++. This is because python is doing some of the work for you, and you did that work upfront when writing the C/C++.
If you are doing something which involves a lot of computation, which all fits in RAM (using numpy in python will make that a fairer test between the two choices), then C/C++ will be faster.
Remember that a good pattern is to write your high-level logic in Python, and write a python implementation of your app, and then profile it to work out the slow parts of the code and speed them up using Cython[1], which will allow you to convert python-like code to efficient C (you can also straight up borrow C/C++ implementations from other people, too). This pattern is designed to balance minimising both programmer-time (since you will only have to code the important bits in C) and run time (since the performance-critical bits can be optimised.)
[1] http://cython.org/ http://cython.org/
(for pedants: I am referring to the CPython implementation, which is the only one which supports C/C++ extensions.)