title: Time a while loop python
body: <p>I'm trying to time a while loop within a while loop, total time it takes to execute, and record the time it takes to do so, every time it loops. I need a way to achieve this using my code if possible, or open to different concepts I may not know of yet. </p>
  
  <pre><code>import random
  import time
  import sys
  
  def main():
  
  
      looperCPU = 500
      start = time.time()
      while (looperCPU != 0):
          #start = time.time()
  
          #this is the computation for 3 secs
          time.sleep(3)
          random_number = random.randint(0,1000)
  
          #Send to printer for processing
          #.75 secs to 4.75 secs to generate a pause before printing
          secondsPause = random.uniform(.75,4.75)
  
  
          #This is the printer function
          printerLooper = True
          while printerLooper == True :
              print("Sleeping for ", secondsPause, " seconds")
              print(random_number)
              printerLooper = False
  
  
          #
          print("total time taken this loop: ", time.time() - start)
          looperCPU -= 1    
  
  
  
  main()
  </code></pre>
  
  <p>The loop will print a time, but I'm very certain it is not taking into account the nested while loop sleep time. How can I allow python to time both while loops, every loop that it will need to do (in this case 500)?</p>