Python Multiprocessing Speed ​​with a Single Process

I found some behavior with python multiprocessing. I have difficulty understanding. When using a pool, even if it is one process, it performs much more, much faster.

Why? Does multiprocessing optimize the code somehow?

import time
from multiprocessing import Pool


fib_input = [24] * 10

def fib(n):
    if n in [0,1]:
        return 1
    return fib(n-1)+fib(n-2)


def main1():
    with Pool(processes=1) as p:
        results = p.map(fib, fib_input)
    print (results)


def main2():
    results = list(map(fib, fib_input))
    print (results)


if __name__ == "__main__":
    start_time = time.time()
    main1()
    print("--- %s seconds ---" % (time.time() - start_time))

    start_time = time.time()
    main2()
    print("--- %s seconds ---" % (time.time() - start_time))

Output:

[75025, 75025, 75025, 75025, 75025, 75025, 75025, 75025, 75025, 75025]
--- 0.47702741622924805 seconds ---
[75025, 75025, 75025, 75025, 75025, 75025, 75025, 75025, 75025, 75025]
--- 7.922452926635742 seconds ---
+4
source share
1 answer

Ok Thanks to the comments, I realized that I am bad. Thanks guys!

Error rookie.

Visual Studio PTVS. . "build" Release, f5 - , , .

cmd . , ctrl-f5 .

.

0