title: Why does a multiprocessing process do the same job twice as long?
body: <p>I am doing some image analyzer within Blender and want to use multiprocessing in order to reduce calculation time. But when I split a list of pixels values into 4 parts between 4 processes, each of which then copy its list inside an invoked function, it turns out that one multiprocessing process do its work on copied list slower than an single process. Why is it so? I have Pentium G4620 with 2 cores and 4 logical processors. And I have to add, when I split the list into 2 parts, the difference is not as significant but nevertheless remains (~5 and ~6.2 sec for a single and a multi- process respectively).</p>
  
  <pre><code>from time import time
  
  def modify(pixels): 
      this_pixels = list(pixels)[:]
  
      start = time()
      for j in range(1000): # in order to do something
          for i in range(len(this_pixels)):
              this_pixels[i] = 1.0
      end = time()
      print(__name__, 'Time for computing the copied list:', round(end-start,2), 'len of list:', len(this_pixels))
  
  if __name__ == '__main__':
      import bpy
      import sys
  
      sys.executable = bpy.app.binary_path_python
      __file__ = bpy.data.texts[0].filepath
  
      from multiprocessing import Process
  
      D = bpy.data
  
      img = D.images[0]
      pixels = img.pixels[:]
  
      pixels1 = img.pixels[:int(len(pixels)/4)]
      pixels2 = img.pixels[int(len(pixels)/4):int(len(pixels)/2)]
      pixels3 = img.pixels[int(len(pixels)/2):int(len(pixels)*3/4)]
      pixels4 = img.pixels[int(len(pixels)*3/4):int(len(pixels))]
  
      p1 = Process(target=modify,args=(pixels1,))
      p2 = Process(target=modify,args=(pixels2,))
      p3 = Process(target=modify,args=(pixels3,))
      p4 = Process(target=modify,args=(pixels4,))
  
      start = time()
  #    modify(pixels1)
  #    modify(pixels2)
  #    modify(pixels3)
  #    modify(pixels4)
  
      p1.start()
      p2.start()
      p3.start()
      p4.start()
      p1.join()
      p2.join()
      p3.join()
      p4.join()
      end = time()
  
      print('Overall time:', round(end-start,2))
  </code></pre>
  
  <p>And the result for ordinary processing and multiprocessing respectively
  :</p>
  
  <pre><code>    __main__ Time for computing the copied list: 2.5 len of list: 66000
      __main__ Time for computing the copied list: 2.52 len of list: 66000
      __main__ Time for computing the copied list: 2.52 len of list: 66000
      __main__ Time for computing the copied list: 2.52 len of list: 66000
      Overall time: 10.08
  
      __mp_main__ Time for computing the copied list: 4.86 len of list: 66000
      __mp_main__ Time for computing the copied list: 4.87 len of list: 66000
      __mp_main__ Time for computing the copied list: 4.8 len of list: 66000
      __mp_main__ Time for computing the copied list: 4.68 len of list: 66000
      Overall time: 5.63
  </code></pre>
  
  <p>EDIT:
  Well, it's interesting. In another similar test, the most significant overall speed-up occurs, if there is splitting between two processes, this took 8.65 sec (compared to 13.88 sec for a single process). Between three processes - 7.66 sec, and between four - the same as for three.</p>
  
  <p>And while there are no benefits of processing with three or four processes, the difference in cpu utilization is significant - 75% and 100% respectively. </p>