title: How to count time elapsed in Python multiple functions
body: <p>I am trying to count how long a very long process is taking:</p>
  
  <pre><code>import datetime
  
  def main(argv):
      starttime = datetime.datetime.now()
      for f in somearray:
          doSomething(f)
      endtime = datetime.datetime.now()
      deltatime = endtime-starttime
      print "Operation took " + str(deltatime.seconds) + " seconds"
  
  def doSomething(f):
      # this takes a looong time (~10 minutes)
  </code></pre>
  
  <p>In the code above I only end up getting the time elapsed for the last time <code>doSomething</code> was run. I used to have <code>doSomething</code> as part of the <code>main</code> function and the timing was fine, but it made sense to move it to its own function.</p>
  
  <p>I saw <a href="https://stackoverflow.com/questions/2245161/how-to-measure-execution-time-of-functions-automatically-in-python">this question</a> but it seems to serve a different need.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Thanks</p>