How could i get execution times ?

Shagshag13 shagshag13 at yahoo.fr
Wed Jun 5 04:58:48 EDT 2002


I'm looking for a way to get execution time at different points of a program, by now i use the
code below, but i've seen in some post that time.clock() could be a better way to measure this,

So my question, is how you pythoners do it ??? and to understand _why_ ?

Thanks

s13.

------
import time

class Chrono:
 def __init__(self):

  self._tags = []
  self._time = []
  self._t0 = time.time()

 def add(self, tag = ''):

  self._time.append(time.time())
  self._tags.append(tag)


 def __str__(self):
  maxL = 0
  for tag in self._tags:
   maxL = max(maxL, len(tag))
  tp = self._t0
  s = ' '
  for i in range(maxL + 13):
   s += '-'
  for i in range(len(self._time)):
   s += "\n " + '['
   for j in range(maxL - len(self._tags[i])):
    s += ' '
   s += self._tags[i]
   s += '] : ' + time.strftime("%H:%M:%S", time.gmtime(self._time[i] - tp))
   tp = self._time[i]
  s += "\n " + '['
  for j in range(maxL):
   s += '='
  try:
   s += '] : ' + time.strftime("%H:%M:%S", time.gmtime(self._time[-1] - self._t0))
  except IndexError:
   pass
  return s





More information about the Python-list mailing list