Commits

Peter Arrenbrecht  committed c5817eb

add timing support

  • Participants
  • Parent commits 08f3d8d

Comments (0)

Files changed (1)

File src/testing.py

 # GNU General Public License version 2, incorporated herein by reference.
 
 import dagutil, dagprinter
-import sys, random
+import sys, random, time
 
 # Required test cases:
 #
     def __init__(self):
         self._stack = []
         self._indent = ''
+        self._lastclock = None
 
     def indent(self, quiesce=False):
         self._stack.append(self._indent)
             self._indent += '  '
 
     def unindent(self):
+        self.done()
         self._indent = self._stack.pop()
 
-    def show(self, s=None, emptyline=False):
+    def show(self, s=None, emptyline=False, newline=True):
         if self._indent is None:
             return
+        if self._lastclock:
+            sys.stdout.write("\n")
         if emptyline:
             sys.stdout.write("\n")
         sys.stdout.write(self._indent)
         sys.stdout.write(s)
-        sys.stdout.write("\n")
+        if newline and not self._lastclock:
+            sys.stdout.write("\n")
 
     def heading(self, title, quiesce=False):
         self.show(title, emptyline=True)
             self.show(title, emptyline=False)
         self.indent(quiesce=quiesce)
 
+    def step(self, title):
+        self.done()
+        self.show(title + "...", newline=False)
+        self._lastclock = time.clock()
+
+    def done(self):
+        if self._lastclock:
+            now = time.clock()
+            sys.stdout.write(" -> %f\n" % (now - self._lastclock))
+            self._lastclock = None
+
 class DiscoveryTests(object):
 
     def __init__(self, writer=None, quiet=False):
         ans, bns = [d.nodeset() for d in dags]
         self.setupdags(a, b, ans, bns)
 
-        self.writer.heading("a (%d) -> b (%d)" % (len(ans), len(bns)), quiesce=self.quiet)
+        aout = ans - bns
+        bout = bns - ans
+        self.writer.heading("a (%d, %d) -> b (%d, %d)" % (len(ans), len(aout), len(bns), len(bout)), quiesce=self.quiet)
         self.test(a, b, ans, bns)
         self.writer.unindent()
 
-        self.writer.heading("b (%d) -> a (%d)" % (len(bns), len(ans)), quiesce=self.quiet)
+        self.writer.heading("b (%d, %d) -> a (%d, %d)" % (len(bns), len(bout), len(ans), len(aout)), quiesce=self.quiet)
         self.test(b, a, bns, ans)
         self.writer.unindent()
 
 
     def testfile(self, fname, pairs=None, n=5):
         self.writer.heading(fname)
+        self.writer.step("parsing...")
         dag = dagutil.MemDAG.fromfile(fname)
+        self.writer.done()
         nodes = dag.nodeset()
         if not pairs:
             pairs = [(dag.headsof(random.sample(nodes, 2)),