The following computation takes about 10.4 seconds on my Precision 5520:
import time
before = time.time()
sum = 0
for i in range(1, 100000000):
sum += i
print(time.time() - before, sum)
On the same laptop, the following takes only 5.2 seconds:
import multiprocessing as mp
import time
def foo():
before = time.time()
sum = 0
for i in range(1, 100000000):
sum += i
print(time.time() - before, sum)
mp.Process(target=foo).start()
This result is consistent. In fact, it holds (with a slightly smaller speed-up factor) even if I run cpu_count processes simultaneously.
So, why would spawning a process make computation run twice as fast?