[Numpy-svn] r5424 - trunk/numpy/testing

numpy-svn@scip... numpy-svn@scip...
Tue Jul 15 19:36:34 CDT 2008


Author: alan.mcintyre
Date: 2008-07-15 19:36:32 -0500 (Tue, 15 Jul 2008)
New Revision: 5424

Modified:
   trunk/numpy/testing/utils.py
Log:
Added the measure function to utils.py in support of SciPy tests.


Modified: trunk/numpy/testing/utils.py
===================================================================
--- trunk/numpy/testing/utils.py	2008-07-15 21:49:36 UTC (rev 5423)
+++ trunk/numpy/testing/utils.py	2008-07-16 00:36:32 UTC (rev 5424)
@@ -363,3 +363,22 @@
         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



More information about the Numpy-svn mailing list