summaryrefslogtreecommitdiff
path: root/numpy/testing/utils.py
diff options
context:
space:
mode:
authorAlan McIntyre <alan.mcintyre@local>2008-07-16 00:36:32 +0000
committerAlan McIntyre <alan.mcintyre@local>2008-07-16 00:36:32 +0000
commite10e7d9ab98f2ad3e8ffc6f63583feb8fbef882a (patch)
treed7a546034f8dd154ef43a1c4bb9f7eda0b0c8b08 /numpy/testing/utils.py
parentdc850ae31bf4937eace3f6b62a615a78bac2d73d (diff)
downloadnumpy-e10e7d9ab98f2ad3e8ffc6f63583feb8fbef882a.tar.gz
Added the measure function to utils.py in support of SciPy tests.
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r--numpy/testing/utils.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py
index 5e0ef06f3..2051bc7bc 100644
--- a/numpy/testing/utils.py
+++ b/numpy/testing/utils.py
@@ -363,3 +363,22 @@ def decorate_methods(cls, decorator, testmatch=None):
if testmatch.search(funcname) and not funcname.startswith('_'):
setattr(cls, funcname, decorator(function))
return
+
+
+def measure(code_str,times=1,label=None):
+ """ Return elapsed time for executing code_str in the
+ namespace of the caller for given times.
+ """
+ frame = sys._getframe(1)
+ locs,globs = frame.f_locals,frame.f_globals
+
+ code = compile(code_str,
+ 'Test name: %s ' % label,
+ 'exec')
+ i = 0
+ elapsed = jiffies()
+ while i<times:
+ i += 1
+ exec code in globs,locs
+ elapsed = jiffies() - elapsed
+ return 0.01*elapsed