title: How do I time a recursive function?
body: <p>I am currently in the works of trying to time a merge sort function.
  The only problem is that the merge sort function is recursive and will return the time every time it was completed.</p>
  
  <p>How can I fix this?</p>
  
  <pre><code>def MergeSort(argShuffledList):
      dblStart = time.clock()
      if len(argShuffledList)&gt;1:
          intMidValue = len(argShuffledList)//2
          listLeftHalf = argShuffledList[:intMidValue]
          listRightHalf = argShuffledList[intMidValue:]
  
          left_part = MergeSort(listLeftHalf)
          right_part = MergeSort(listRightHalf)
  
  
          i=0
          j=0
          k=0
          while i &lt; len(listLeftHalf) and j &lt; len(listRightHalf):
  
              if listLeftHalf[i] &lt; listRightHalf[j]:
                  argShuffledList[k]=listLeftHalf[i]
                  i =i+1
  
              else:
                  argShuffledList[k]=listRightHalf[j]
                  j=j+1
  
              k=k+1
  
          while i &lt; len(listLeftHalf):
              argShuffledList[k]=listLeftHalf[i]
              i=i+1
              k=k+1
  
  
          while j &lt; len(listRightHalf):
              argShuffledList[k]=listRightHalf[j]
              j=j+1
              k=k+1
  
  
      intTime = "%.2f" % ((time.clock() - dblStart) * 1000000)
      message = "Elasped Time: " + str(intTime) + " microseconds"
      print("Selection Sort: ", argShuffledList)
      print(message, "\n")
  </code></pre>