Author: duncan
Date: Sun Mar 16 06:30:00 2008
New Revision: 10532

Log:
Made _indentation a class varible, nicer than a global
Added some more information to the tests


Modified:
   branches/rel-1/freevo/src/util/benchmark.py

Modified: branches/rel-1/freevo/src/util/benchmark.py
==============================================================================
--- branches/rel-1/freevo/src/util/benchmark.py (original)
+++ branches/rel-1/freevo/src/util/benchmark.py Sun Mar 16 06:30:00 2008
@@ -31,14 +31,14 @@
 
 import time
 
-_indentation = 0
-
 
 class benchmark:
     """
     A decorator class to time function calls
     http://wiki.python.org/moin/PythonDecoratorLibrary
     """
+    _indentation = 0
+
     def __init__(self, reset=True):
         """ Contructs the benchmark class
         @param reset: resets the timer a each call
@@ -49,9 +49,8 @@
 
     def __call__(self, func):
         def newfunc(*args, **kwargs):
-            global _indentation
-            indentation = '  ' * _indentation
-            _indentation += 1
+            indentation = '  ' * benchmark._indentation
+            benchmark._indentation += 1
             if self.reset:
                 self.start = time.time()
             print '%s-> %s' % (indentation, func.__name__)
@@ -59,7 +58,7 @@
                 result = func(*args, **kwargs)
             finally:
                 print '%s<- %s: %.3f' % (indentation, func.__name__, 
time.time() - self.start)
-                _indentation -= 1
+                benchmark._indentation -= 1
             return result
         newfunc.__name__ = func.__name__
         newfunc.__doc__ = func.__doc__
@@ -94,4 +93,10 @@
     print '__repr__:', longrunning
     print '__name__:', longrunning.__name__
     print '__doc__:', longrunning.__doc__
-    failure()
+    try:
+        failure()
+    except:
+        import traceback
+        traceback.print_exc()
+    print '__name__:', failure.__name__
+    print '__doc__:', failure.__doc__

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to