Getting time from the system

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #16
    Originally posted by psbasha
    Thanks Barton,
    This is what I am looking for.
    I need this functionality for finding out ,how much time my application is taking for execution.Based on the more time taken I have to find out which function is taking more time ( similar to profiling).

    -PSB
    You are welcome. It looks like you skills are growing. Keep it up.

    Comment

    • bvdet
      Recognized Expert Specialist
      • Oct 2006
      • 2851

      #17
      Originally posted by psbasha
      Thanks Barton,
      This is what I am looking for.
      I need this functionality for finding out ,how much time my application is taking for execution.Based on the more time taken I have to find out which function is taking more time ( similar to profiling).

      -PSB
      Here's an alternate method:
      Code:
      from time import sleep
      import time
      
      def formatSec(seconds):
          milli = int(seconds%1*1000)
          days = float(seconds)/86400
          hours = days%1*24
          minutes = hours%1*60
          seconds = minutes%1*60
          if int(days) > 0:
              outStr = '%d days,' % days
          else:
              outStr = ''
          outStr = ''.join([outStr, '%02d:%02d:%02d' % (hours, minutes, seconds)])
          if milli > 0:
              outStr += ' and %d milliseconds' % milli
          return outStr
      
      if __name__ == '__main__':
          t1 = time.time()
          time.sleep(3.75)
          t2 = time.time()
          print formatSec(t2-t1)
      
      # >>> 00:00:03 and 750 milliseconds

      Comment

      Working...