ATLAS Offline Software
rtime.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 
3 #
4 # $Id: rtime.py,v 1.1 2005-05-06 22:44:59 ssnyder Exp $
5 # File: normphi.py
6 # Created: sss, 2004.
7 # Purpose: Measure the execution time of a function.
8 #
9 
10 from __future__ import print_function
11 
12 import resource
13 
14 
15 def rtime (fn, *args, **kw):
16  """Call FN with the additional arguments passed in.
17 Print a report of the CPU time taken.
18 """
19  ru0 = resource.getrusage (resource.RUSAGE_SELF)
20  ret = None
21  try:
22  ret = fn (*args, **kw)
23  finally:
24  ru1 = resource.getrusage (resource.RUSAGE_SELF)
25  print ("utime: %f, stime: %f" % (ru1.ru_utime-ru0.ru_utime,
26  ru1.ru_stime-ru0.ru_stime))
27  return ret
28 
29 
python.rtime.rtime
def rtime(fn, *args, **kw)
Definition: rtime.py:15