title: Why is the following simple parallelized code much slower than a simple loop in Python?
body: <p>A simple program which calculates square of numbers and stores the results:</p>
  
  <pre><code>    import time
      from joblib import Parallel, delayed
      import multiprocessing
  
      array1 = [ 0 for i in range(100000) ]
  
      def myfun(i):
          return i**2
  
      #### Simple loop ####
      start_time = time.time()
  
      for i in range(100000):
          array1[i]=i**2
  
      print( "Time for simple loop         --- %s seconds ---" % (  time.time()
                                                                 - start_time
                                                                   )
              )
      #### Parallelized loop ####
      start_time = time.time()
      results = Parallel( n_jobs  = -1,
                          verbose =  0,
                          backend = "threading"
                          )(
                          map( delayed( myfun ),
                               range( 100000 )
                               )
                          )
      print( "Time for parallelized method --- %s seconds ---" % (  time.time()
                                                                 - start_time
                                                                   )
              )
  </code></pre>
  
  <hr>
  
  <pre><code>    #### Output ####
      # &gt;&gt;&gt; ( executing file "Test_vr20.py" )
      # Time for simple loop         --- 0.015599966049194336 seconds ---
      # Time for parallelized method --- 7.763299942016602 seconds ---
  </code></pre>
  
  <p>Could it be the difference in array handling for the two options? My actual program would have something more complicated but <strong>this is the kind of calculation that I need to parallelize, as simply as possible</strong>, but not with such results.</p>
  
  <pre><code>System Model: HP ProBook 640 G2, Windows 7,
                IDLE for Python System Type: x64-based PC Processor:
                Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz,
                2401 MHz,
                2 Core(s),
                4 Logical Processor(s)
  </code></pre>