R
R
Rishat Sultanov2017-10-10 20:38:47
Python
Rishat Sultanov, 2017-10-10 20:38:47

CPU idle due to interpreter?

Hello!
I just can’t put it in my head who doesn’t have time to process the recursion of a terrible algorithm. Python or my processor.
On board:
Intel® Core™ i7-6900K Processor
At startup:

def fib(n):
    if n <= 1:
        return n
    else:
        return fib(n-1)+fib(n-2)

The load is:
59dd0588e91c7830762634.png
Why so simple?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2017-10-10
@rishatss

Not every task can be parallelized. If possible, then you should look at one of these libraries https://docs.python.org/3/library/threading.html and https://docs.python.org/3.6/library/multiprocessin... I would look in the direction of multiprocessing, since multithreading in python is terribly slow due to blocking by threads of each other, 100% of the processor cannot be squeezed out on threads, you can google this problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question