educative.io

Comparison between Single Threaded vs Multi Threaded vs Multi Processing

In the introduction, there is a code snippet which states the following values:

Single Thread 9.9
Multiple Threads 12.3
Multiple Processes 13.1

Which is Multiple Processes > Multiple Threads > Single Thread.

The results when I run this code snippet online is quite different:

single threaded took : 8.91895413399 seconds and summed to 450000015000000
multiple threads took : 7.67343401909 seconds and summed to 450000015000000
multiple processes took : 9.27198815346 seconds and summed to 450000015000000

Which is, Multiple Processes > Single Threaded > Multiple Threads.
I tried the same code snippet on my system and the result is as follows:

System has 12 CPUs
single threaded took : 3.523620128631592 seconds and summed to 450000015000000
multiple threads took : 3.339877128601074 seconds and summed to 450000015000000
multiple processes took : 3.3494582176208496 seconds and summed to 450000015000000

Here: Single Threaded > Multiple Processes > Multiple Thread

Why this variation?

1 Like