Python, using multiprocess is slower than not using it

前端 未结 4 1007
情话喂你
情话喂你 2020-12-29 13:04

After spending a lot of time trying to wrap my head around multiprocessing I came up with this code which is a benchmark test:

Example 1:

         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-29 13:43

    This example is too small to benefit from multiprocessing.

    There's a LOT of overhead when starting a new process. If there were heavy processing involved, it would be negligable. But your example really isn't all that intensive, and so you're bound to notice the overhead.

    You'd probably notice a bigger difference with real threads, too bad python (well, CPython) has issues with CPU-bound threading.

提交回复
热议问题