/usr/share/pyshared/application/debug/timing.py is in python-application 1.2.8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | # Copyright (C) 2006-2007 Dan Pascu. See LICENSE for details.
#
"""Measure code execution time for benchmarking and profiling purposes.
Usage:
from application.debug.timing import timer
count = 10000
t = timer(count)
for x in xrange(count):
...
t.end(msg="executing loop type 1")
"""
from time import time
class timer(object):
def __init__(self, count):
self.count = count
self.start = time()
def end(self, duration=True, rate=True, msg=None):
_duration = time() - self.start
_rate = self.count/_duration
if duration:
format = "time = %(_duration)5.2f sec"
else:
format = ""
if rate:
format += "; rate = %(_rate)d requests/sec"
if msg is not None:
format += "; %(msg)s"
print format % locals()
|