title: Python: For loop Vs. Map
body: <p>I am currently in the process of optimising the translation part of my software, which translates co-ordinates <code>x</code> amount of times. My current translation code is in the <code>translate</code> function and the supposedly optimised portion in the <code>translate_map</code> function. </p>
  
  <p>I read <a href="http://wiki.python.org/moin/PythonSpeed/PerformanceTips" rel="nofollow">here</a> that the <code>map</code> function should be used instead of <code>for</code> loops where possible because the loop is performed in C.</p>
  
  <p>When I run a test case below, the <code>map</code> function actually runs slower than a standard <code>for</code> loop. Why does the <code>map</code> perform slower than the conventional <code>for</code> loop? How could I optimise the translate function to run faster?</p>
  
  <pre><code>import time
  
  def translate(atom_list):
      for i in atom_list:
          i[1]+=1
          i[2]+=1
          i[3]+=1
  
  atoms = [[1,1,1,1]]*1000
  start = time.time()
  for x in xrange(10000):
      translate(atoms)
  print time.time() - start
  
  
  atoms = [[1,1,1,1]]*1000
  start = time.time()
  def translate_map(atom_list):
      atom_list[1]+=1
      atom_list[2]+=1
      atom_list[3]+=1
  for x in xrange(10000):
      map(translate_map,atoms)
  print time.time() - start
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>2.92705798149
  4.14674210548
  </code></pre>