Just a personal feeling, write some computationally intense code, C + + version is fast, and Python version is much slower. But the strange point is that the Python version generally does not occupy all the CPU resources, and C + + is 100%, is there any way to make Python code more efficient call CPU resources? (within the Python framework, the Cython or python-c API is not considered)
Reply content:
The correct solution is that the problem of pure computing should be written in C + +, and then you learn how to connect any two programming languages to each other, and then never think about this boring problem. This is my task when I use Matplotlib to draw the most recent stock trend.
Python can only get a lot of progress if it wants to fill up the CPU without the C extension. A computationally intensive problem that requires a large amount of data exchange between threads, suitable for shared memory ... It's wiser to abandon Python. Of course, many data-parallel types of numerical computing problems, there is no need to abandon the Python write C extension, you can consider the numba/theano/numexpr and other optimization tools. Look at the symptoms, the main problem is that the C + + version may be in the internal call a multi-threaded, python in the case of the Gil, at most can only occupy one core, so there will be how to run the question of dissatisfaction
The above answer is very good, to fill the kernel please Cython, take on the Nogil:
Search Results GitHub
Python is supposed to be used for casual work. If not most of the CLI shell programming syntax is not modern enough, Python is not as good as those shells (people will not make a version of the big split) I accidentally see the programmer how not to eat cpu_ (: _"∠) _ Sorry to ask the main C + + occupied 100%cpu, you sure the program is written right? Multi-use Numpy...python has a global lock, a Pyhton program can only occupy a CPU at any time, of course, on this CPU, you can run full 100%, for the current multi-CPU system, want to make full use of CPU resources, you can only choose to use multi-process technology ( Multithreading is not good, too.) There are many ways to speed up, such as writing C expansion, using the PyPy compiler, optimizing the code structure, and so on. Why don't you multiprocessing?