ATLAS Offline Software
Loading...
Searching...
No Matches
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
11import resource
12
13
14def rtime (fn, *args, **kw):
15 """Call FN with the additional arguments passed in.
16Print a report of the CPU time taken.
17"""
18 ru0 = resource.getrusage (resource.RUSAGE_SELF)
19 ret = None
20 try:
21 ret = fn (*args, **kw)
22 finally:
23 ru1 = resource.getrusage (resource.RUSAGE_SELF)
24 print ("utime: %f, stime: %f" % (ru1.ru_utime-ru0.ru_utime,
25 ru1.ru_stime-ru0.ru_stime))
26 return ret
27
28