diff options
author | Alan McIntyre <alan.mcintyre@local> | 2008-07-16 00:36:32 +0000 |
---|---|---|
committer | Alan McIntyre <alan.mcintyre@local> | 2008-07-16 00:36:32 +0000 |
commit | e10e7d9ab98f2ad3e8ffc6f63583feb8fbef882a (patch) | |
tree | d7a546034f8dd154ef43a1c4bb9f7eda0b0c8b08 /numpy/testing/utils.py | |
parent | dc850ae31bf4937eace3f6b62a615a78bac2d73d (diff) | |
download | numpy-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.py | 19 |
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 |